Whamcloud - gitweb
7d1b9a8d143437cfb76b5e8f5b3b2939e2e6b52c
[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  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *   Author: Peter J. Braam <braam@clusterfs.com>
6  *   Author: Phil Schwan <phil@clusterfs.com>
7  *   Author: Andreas Dilger <adilger@clusterfs.com>
8  *   Author: Robert Read <rread@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org.
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  */
26
27
28 #include <stdlib.h>
29 #include <sys/ioctl.h>
30 #include <stdio.h>
31 #include <stdarg.h>
32
33 #ifndef __KERNEL__
34 #include <liblustre.h>
35 #endif
36 #include <linux/lustre_lib.h>
37 #include <linux/lustre_cfg.h>
38 #include <linux/lustre_idl.h>
39 #include <linux/lustre_dlm.h>
40 #include <linux/obd.h>          /* for struct lov_stripe_md */
41 #include <linux/lustre_build_version.h>
42
43 #include <unistd.h>
44 #include <sys/un.h>
45 #include <time.h>
46 #include <sys/time.h>
47 #include <errno.h>
48 #include <string.h>
49
50
51 #include "obdctl.h"
52 #include <portals/ptlctl.h>
53 #include "parser.h"
54 #include <stdio.h>
55
56 static char *lcfg_devname;
57
58 void lcfg_set_devname(char *name)
59 {
60         if (lcfg_devname)
61                 free(lcfg_devname);
62         lcfg_devname = strdup(name);
63 }
64
65
66 int jt_lcfg_device(int argc, char **argv)
67 {
68         char *name;
69
70         if (argc == 1) {
71                 printf("current device is %s\n", lcfg_devname? : "not set");
72                 return 0;
73         } else if (argc != 2) {
74                 return CMD_HELP;
75         }
76
77         name = argv[1];
78
79         /* quietly strip the unnecessary '$' */
80         if (*name == '$')
81                 name++;
82
83         lcfg_set_devname(name);
84
85         return 0;
86 }
87
88 /* NOOP */
89 int jt_lcfg_newdev(int argc, char **argv)
90 {
91         return 0;
92 }
93
94 int jt_lcfg_attach(int argc, char **argv)
95 {
96         struct lustre_cfg_bufs bufs;
97         struct lustre_cfg *lcfg;
98         int rc;
99
100         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
101
102         if (argc != 2 && argc != 3 && argc != 4)
103                 return CMD_HELP;
104
105         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
106         if (argc >= 3) {
107                 lustre_cfg_bufs_set_string(&bufs, 0, argv[2]);
108         } else {
109                 fprintf(stderr, "error: %s: LCFG_ATTACH requires a name\n",
110                         jt_cmdname(argv[0]));
111                 return -EINVAL;
112         }
113
114         if (argc == 4) {
115                 lustre_cfg_bufs_set_string(&bufs, 2, argv[3]);
116         }
117         lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
118         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
119         lustre_cfg_free(lcfg);
120         if (rc < 0) {
121                 fprintf(stderr, "error: %s: LCFG_ATTACH %s\n",
122                         jt_cmdname(argv[0]), strerror(rc = errno));
123         } else if (argc == 3) {
124                 char name[1024];
125
126                 lcfg_set_devname(argv[2]);
127                 if (strlen(argv[2]) > 128) {
128                         printf("Name too long to set environment\n");
129                         return -EINVAL;
130                 }
131                 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
132                 rc = setenv(name, argv[1], 1);
133                 if (rc) {
134                         printf("error setting env variable %s\n", name);
135                 }
136         } else {
137                 lcfg_set_devname(argv[2]);
138         }
139
140         return rc;
141 }
142
143 int jt_lcfg_setup(int argc, char **argv)
144 {
145         struct lustre_cfg_bufs bufs;
146         struct lustre_cfg *lcfg;
147         int rc, i;
148
149         if (lcfg_devname == NULL) {
150                 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
151                         "device name for config commands.\n",
152                         jt_cmdname(argv[0]));
153                 return -EINVAL;
154         }
155
156         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
157         
158         if (argc > 7)
159                 return CMD_HELP;
160
161         for (i = 1; i < argc; i++) {
162                 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
163         }
164
165         lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
166         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
167         lustre_cfg_free(lcfg);
168         if (rc < 0)
169                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
170                         strerror(rc = errno));
171
172         return rc;
173 }
174
175 int jt_obd_detach(int argc, char **argv)
176 {
177         struct lustre_cfg_bufs bufs;
178         struct lustre_cfg *lcfg;
179         int rc;
180
181         if (lcfg_devname == NULL) {
182                 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
183                         "device name for config commands.\n",
184                         jt_cmdname(argv[0]));
185                 return -EINVAL;
186         }
187         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
188
189         if (argc != 1)
190                 return CMD_HELP;
191
192         lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
193         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
194         lustre_cfg_free(lcfg);
195
196         if (rc < 0)
197                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
198                         strerror(rc = errno));
199         return rc;
200 }
201
202 int jt_obd_cleanup(int argc, char **argv)
203 {
204         struct lustre_cfg_bufs bufs;
205         struct lustre_cfg *lcfg;
206         char force = 'F';
207         char failover = 'A';
208         char flags[3];
209         int flag_cnt = 0, n;
210         int rc;
211
212
213
214         if (lcfg_devname == NULL) {
215                 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
216                         "device name for config commands.\n",
217                         jt_cmdname(argv[0]));
218                 return -EINVAL;
219         }
220
221         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
222
223         if (argc < 1 || argc > 3)
224                 return CMD_HELP;
225
226         /* we are protected from overflowing our buffer by the argc
227          * check above
228          */
229         for (n = 1; n < argc; n++) {
230                 if (strcmp(argv[n], "force") == 0) {
231                         flags[flag_cnt++] = force;
232                 } else if (strcmp(argv[n], "failover") == 0) {
233                         flags[flag_cnt++] = failover;
234                 } else {
235                         fprintf(stderr, "unknown option: %s", argv[n]);
236                         return CMD_HELP;
237                 }
238         }
239
240         if (flag_cnt) {
241                 lustre_cfg_bufs_set_string(&bufs, 1, flags);
242         }
243
244         lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
245         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
246         lustre_cfg_free(lcfg);
247         if (rc < 0)
248                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
249                         strerror(rc = errno));
250
251         return rc;
252 }
253
254 static
255 int do_add_uuid(char * func, char *uuid, ptl_nid_t nid, int nal)
256 {
257         char tmp[64];
258         int rc;
259         struct lustre_cfg_bufs bufs;
260         struct lustre_cfg *lcfg;
261
262         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
263         if (uuid)
264                 lustre_cfg_bufs_set_string(&bufs, 1, uuid);
265
266         lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
267         lcfg->lcfg_nid = nid;
268         lcfg->lcfg_nal = nal;
269
270         rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg);
271         lustre_cfg_free(lcfg);
272         if (rc) {
273                 fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
274                         strerror(errno));
275                 return -1;
276         }
277
278         printf ("Added uuid %s: %s\n", uuid, ptl_nid2str (tmp, nid));
279         return 0;
280
281 }
282
283 int jt_lcfg_add_uuid(int argc, char **argv)
284 {
285         ptl_nid_t nid = 0;
286         int nal;
287
288         if (argc != 4) {
289                 return CMD_HELP;
290         }
291
292         if (ptl_parse_nid (&nid, argv[2]) != 0) {
293                 fprintf (stderr, "Can't parse NID %s\n", argv[2]);
294                         return (-1);
295         }
296
297         nal = ptl_name2nal(argv[3]);
298
299         if (nal <= 0) {
300                 fprintf (stderr, "Can't parse NAL %s\n", argv[3]);
301                 return -1;
302         }
303
304         return do_add_uuid(argv[0], argv[1], nid, nal);
305 }
306
307 int obd_add_uuid(char *uuid, ptl_nid_t nid, int nal)
308 {
309         return do_add_uuid("obd_add_uuid", uuid, nid, nal);
310 }
311
312 int jt_lcfg_del_uuid(int argc, char **argv)
313 {
314         int rc;
315         struct lustre_cfg_bufs bufs;
316         struct lustre_cfg *lcfg;
317
318         if (argc != 2) {
319                 fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
320                 return 0;
321         }
322
323         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
324         if (strcmp (argv[1], "_all_"))
325                 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
326
327         lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
328         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
329         lustre_cfg_free(lcfg);
330         if (rc) {
331                 fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
332                         strerror(errno));
333                 return -1;
334         }
335         return 0;
336 }
337
338 int jt_lcfg_lov_setup(int argc, char **argv)
339 {
340         struct lustre_cfg_bufs bufs;
341         struct lustre_cfg *lcfg;
342         struct lov_desc desc;
343         int rc;
344         char *end;
345
346         /* argv: lov_setup <LOV uuid> <stripe count> <stripe size>
347          *                 <stripe offset> <pattern>
348          */
349         if (argc != 6)
350                 return CMD_HELP;
351
352         if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
353                 fprintf(stderr,
354                         "error: %s: LOV uuid '%s' longer than "LPSZ" chars\n",
355                         jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
356                 return -EINVAL;
357         }
358
359         memset(&desc, 0, sizeof(desc));
360         obd_str2uuid(&desc.ld_uuid, argv[1]);
361         desc.ld_default_stripe_count = strtoul(argv[2], &end, 0);
362         if (*end) {
363                 fprintf(stderr, "error: %s: bad default stripe count '%s'\n",
364                         jt_cmdname(argv[0]), argv[2]);
365                 return CMD_HELP;
366         }
367
368         desc.ld_default_stripe_size = strtoull(argv[3], &end, 0);
369         if (*end) {
370                 fprintf(stderr, "error: %s: bad default stripe size '%s'\n",
371                         jt_cmdname(argv[0]), argv[3]);
372                 return CMD_HELP;
373         }
374         if (desc.ld_default_stripe_size < 4096) {
375                 fprintf(stderr,
376                         "error: %s: default stripe size "LPU64" too small\n",
377                         jt_cmdname(argv[0]), desc.ld_default_stripe_size);
378                 return -EINVAL;
379         } else if ((long)desc.ld_default_stripe_size <
380                    desc.ld_default_stripe_size) {
381                 fprintf(stderr,
382                         "error: %s: default stripe size "LPU64" too large\n",
383                         jt_cmdname(argv[0]), desc.ld_default_stripe_size);
384                 return -EINVAL;
385         }
386
387         desc.ld_default_stripe_offset = strtoull(argv[4], &end, 0);
388         if (*end) {
389                 fprintf(stderr, "error: %s: bad default stripe offset '%s'\n",
390                         jt_cmdname(argv[0]), argv[4]);
391                 return CMD_HELP;
392         }
393
394         desc.ld_pattern = strtoul(argv[5], &end, 0);
395         if (*end) {
396                 fprintf(stderr, "error: %s: bad stripe pattern '%s'\n",
397                         jt_cmdname(argv[0]), argv[5]);
398                 return CMD_HELP;
399         }
400
401         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
402         lustre_cfg_bufs_set(&bufs, 1, &desc, sizeof(desc));
403
404         lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
405         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
406         lustre_cfg_free(lcfg);
407         if (rc)
408                 fprintf(stderr, "error: %s: ioctl error: %s\n",
409                         jt_cmdname(argv[0]), strerror(rc = errno));
410         return rc;
411 }
412
413 int jt_lcfg_lmv_setup(int argc, char **argv)
414 {
415         struct lustre_cfg_bufs bufs;
416         struct lustre_cfg *lcfg;
417         struct lmv_desc desc;
418         struct obd_uuid *uuidarray, *ptr;
419         int rc, i;
420
421         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
422         if (argc <= 2)
423                 return CMD_HELP;
424
425         if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
426                 fprintf(stderr,
427                         "error: %s: LMV uuid '%s' longer than "LPSZ" chars\n",
428                         jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
429                 return -EINVAL;
430         }
431
432         memset(&desc, 0, sizeof(desc));
433         obd_str2uuid(&desc.ld_uuid, argv[1]);
434         desc.ld_tgt_count = argc - 2;
435         printf("LMV: %d uuids:\n", desc.ld_tgt_count);
436
437         /* NOTE: it is possible to overwrite the default striping parameters,
438          *       but EXTREME care must be taken when saving the OST UUID list.
439          *       It must be EXACTLY the same, or have only additions at the
440          *       end of the list, or only overwrite individual OST entries
441          *       that are restored from backups of the previous OST.
442          */
443         uuidarray = calloc(desc.ld_tgt_count, sizeof(*uuidarray));
444         if (!uuidarray) {
445                 fprintf(stderr, "error: %s: no memory for %d UUIDs\n",
446                         jt_cmdname(argv[0]), desc.ld_tgt_count);
447                 rc = -ENOMEM;
448                 goto out;
449         }
450         for (i = 2, ptr = uuidarray; i < argc; i++, ptr++) {
451                 if (strlen(argv[i]) >= sizeof(*ptr)) {
452                         fprintf(stderr, "error: %s: arg %d (%s) too long\n",
453                                 jt_cmdname(argv[0]), i, argv[i]);
454                         rc = -EINVAL;
455                         goto out;
456                 }
457                 printf("  %s\n", argv[i]);
458                 strcpy((char *)ptr, argv[i]);
459         }
460
461         lustre_cfg_bufs_set(&bufs, 1, &desc, sizeof(desc));
462         lustre_cfg_bufs_set(&bufs, 2, (char*)uuidarray, 
463                             desc.ld_tgt_count * sizeof(*uuidarray));
464         lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
465         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
466         lustre_cfg_free(lcfg);
467         
468         if (rc)
469                 fprintf(stderr, "error: %s: ioctl error: %s\n",
470                         jt_cmdname(argv[0]), strerror(rc = errno));
471 out:
472         free(uuidarray);
473         return rc;
474 }
475 int jt_lcfg_lov_modify_tgts(int argc, char **argv)
476 {
477         struct lustre_cfg_bufs bufs;
478         struct lustre_cfg *lcfg;
479         char *end;
480         int cmd = 0;
481         int index;
482         int gen;
483         int rc;
484
485         /* argv: lov_modify_tgts <op> <LOV name> <OBD uuid> <index> <gen> */
486         if (argc != 6)
487                 return CMD_HELP;
488
489         if (!strncmp(argv[1], "add", 4)) {
490                 cmd = LCFG_LOV_ADD_OBD;
491         } else if (!strncmp(argv[1], "del", 4)) {
492                 cmd = LCFG_LOV_DEL_OBD;
493         } else {
494                 fprintf(stderr, "error: %s: bad operation '%s'\n",
495                         jt_cmdname(argv[0]), argv[1]);
496                 return CMD_HELP;
497         }
498
499         lustre_cfg_bufs_reset(&bufs, argv[2]);
500
501
502         if (((index = strlen(argv[3]) + 1)) > sizeof(struct obd_uuid)) {
503                 fprintf(stderr,
504                         "error: %s: OBD uuid '%s' longer than "LPSZ" chars\n",
505                         jt_cmdname(argv[0]), argv[3],
506                         sizeof(struct obd_uuid) - 1);
507                 return -EINVAL;
508         }
509         lustre_cfg_bufs_set(&bufs, 1, argv[3], index);
510         
511         index = strtoul(argv[4], &end, 0);
512         if (*end) {
513                 fprintf(stderr, "error: %s: bad OBD index '%s'\n",
514                         jt_cmdname(argv[0]), argv[4]);
515                 return CMD_HELP;
516         }
517         lustre_cfg_bufs_set(&bufs, 2, argv[4], strlen(argv[4]));
518
519         gen = strtoul(argv[5], &end, 0);
520         if (*end) {
521                 fprintf(stderr, "error: %s: bad OBD generation '%s'\n",
522                         jt_cmdname(argv[0]), argv[5]);
523                 return CMD_HELP;
524         }
525         lustre_cfg_bufs_set(&bufs, 3, argv[5], strlen(argv[5]));
526
527         lcfg = lustre_cfg_new(cmd, &bufs);
528         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
529         lustre_cfg_free(lcfg);
530         if (rc)
531                 fprintf(stderr, "error: %s: ioctl error: %s\n",
532                         jt_cmdname(argv[0]), strerror(rc = errno));
533         return rc;
534 }
535
536 int jt_lcfg_mount_option(int argc, char **argv)
537 {
538         int rc;
539         struct lustre_cfg_bufs bufs;
540         struct lustre_cfg *lcfg;
541         int i;
542
543         if (argc < 3 || argc > 5)
544                 return CMD_HELP;
545
546         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
547
548         for (i = 1; i < argc; i++)
549                 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
550
551         lcfg = lustre_cfg_new(LCFG_MOUNTOPT, &bufs);
552         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
553         lustre_cfg_free(lcfg);
554         if (rc < 0) {
555                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
556                         strerror(rc = errno));
557         }
558         return rc;
559 }
560
561 int jt_lcfg_del_mount_option(int argc, char **argv)
562 {
563         int rc;
564         struct lustre_cfg_bufs bufs;
565         struct lustre_cfg *lcfg;
566
567         if (argc != 2)
568                 return CMD_HELP;
569
570         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
571
572         /* profile name */
573         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
574
575         lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
576         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
577         lustre_cfg_free(lcfg);
578         if (rc < 0) {
579                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
580                         strerror(rc = errno));
581         }
582         return rc;
583 }
584
585 int jt_lcfg_set_timeout(int argc, char **argv)
586 {
587         int rc;
588         struct lustre_cfg_bufs bufs;
589         struct lustre_cfg *lcfg;
590
591         if (argc != 2)
592                 return CMD_HELP;
593
594         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
595         lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
596         lcfg->lcfg_num = atoi(argv[1]);
597
598         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
599         lustre_cfg_free(lcfg);
600         if (rc < 0) {
601                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
602                         strerror(rc = errno));
603         }
604         return rc;
605 }
606
607
608 int jt_lcfg_set_lustre_upcall(int argc, char **argv)
609 {
610         int rc;
611         struct lustre_cfg_bufs bufs;
612         struct lustre_cfg *lcfg;
613
614         if (argc != 2)
615                 return CMD_HELP;
616
617         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
618
619         /* profile name */
620         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
621
622         lcfg = lustre_cfg_new(LCFG_SET_UPCALL, &bufs);
623         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
624         lustre_cfg_free(lcfg);
625         if (rc < 0) {
626                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
627                         strerror(rc = errno));
628         }
629         return rc;
630 }
631
632 int jt_lcfg_add_conn(int argc, char **argv)
633 {
634         struct lustre_cfg_bufs bufs;
635         struct lustre_cfg *lcfg;
636         int priority;
637         int rc;
638
639         if (argc == 2)
640                 priority = 0;
641         else if (argc == 3)
642                 priority = 1;
643         else
644                 return CMD_HELP;
645
646         if (lcfg_devname == NULL) {
647                 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
648                         "device name for config commands.\n",
649                         jt_cmdname(argv[0]));
650                 return -EINVAL;
651         }
652
653         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
654
655         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
656
657         lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs);
658         lcfg->lcfg_num = priority;
659
660         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
661         lustre_cfg_free (lcfg);
662         if (rc < 0) {
663                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
664                         strerror(rc = errno));
665         }
666         return rc;
667 }
668
669 int jt_lcfg_del_conn(int argc, char **argv)
670 {
671         struct lustre_cfg_bufs bufs;
672         struct lustre_cfg *lcfg;
673         int rc;
674
675         if (argc != 2)
676                 return CMD_HELP;
677
678         if (lcfg_devname == NULL) {
679                 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
680                         "device name for config commands.\n",
681                         jt_cmdname(argv[0]));
682                 return -EINVAL;
683         }
684
685         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
686
687         /* connection uuid */
688         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
689
690         lcfg = lustre_cfg_new(LCFG_DEL_CONN, &bufs);
691
692         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
693         lustre_cfg_free(lcfg);
694         if (rc < 0) {
695                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
696                         strerror(rc = errno));
697         }
698
699         return rc;
700 }
701
702 int jt_lcfg_set_security(int argc, char **argv)
703 {
704         struct lustre_cfg_bufs bufs;
705         struct lustre_cfg *lcfg;
706         int rc;
707
708         if (argc != 3)
709                 return CMD_HELP;
710
711         if (lcfg_devname == NULL) {
712                 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
713                         "device name for config commands.\n",
714                         jt_cmdname(argv[0]));
715                 return -EINVAL;
716         }
717
718         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
719
720         /* currently only used to set on mds */
721         if (strcmp(argv[1], "mds_sec") &&
722             strcmp(argv[1], "oss_sec") &&
723             strcmp(argv[1], "deny_sec")) {
724                 fprintf(stderr, "%s: invalid security key %s\n",
725                         jt_cmdname(argv[0]), argv[1]);
726                 return -EINVAL;
727         }
728         if (strcmp(argv[2], "null") &&
729             strcmp(argv[2], "krb5i") &&
730             strcmp(argv[2], "krb5p")) {
731                 fprintf(stderr, "%s: invalid security value %s\n",
732                         jt_cmdname(argv[0]), argv[2]);
733                 return -EINVAL;
734         }
735
736         /* connection uuid */
737         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
738         lustre_cfg_bufs_set_string(&bufs, 2, argv[2]);
739         lcfg = lustre_cfg_new(LCFG_SET_SECURITY, &bufs);        
740
741         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
742         lustre_cfg_free(lcfg);
743         if (rc < 0) {
744                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
745                         strerror(rc = errno));
746         }
747
748         return rc;
749 }
750
751