1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
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>
10 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
29 #include <sys/ioctl.h>
34 #include <liblustre.h>
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>
52 #include <portals/ptlctl.h>
56 static char *lcfg_devname;
58 void lcfg_set_devname(char *name)
62 lcfg_devname = strdup(name);
66 int jt_lcfg_device(int argc, char **argv)
71 printf("current device is %s\n", lcfg_devname? : "not set");
73 } else if (argc != 2) {
79 /* quietly strip the unnecessary '$' */
83 lcfg_set_devname(name);
89 int jt_lcfg_newdev(int argc, char **argv)
94 int jt_lcfg_attach(int argc, char **argv)
96 struct lustre_cfg_bufs bufs;
97 struct lustre_cfg *lcfg;
100 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
102 if (argc != 2 && argc != 3 && argc != 4)
105 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
107 lustre_cfg_bufs_set_string(&bufs, 0, argv[2]);
109 fprintf(stderr, "error: %s: LCFG_ATTACH requires a name\n",
110 jt_cmdname(argv[0]));
115 lustre_cfg_bufs_set_string(&bufs, 2, argv[3]);
117 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
118 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
119 lustre_cfg_free(lcfg);
121 fprintf(stderr, "error: %s: LCFG_ATTACH %s\n",
122 jt_cmdname(argv[0]), strerror(rc = errno));
123 } else if (argc == 3) {
126 lcfg_set_devname(argv[2]);
127 if (strlen(argv[2]) > 128) {
128 printf("Name too long to set environment\n");
131 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
132 rc = setenv(name, argv[1], 1);
134 printf("error setting env variable %s\n", name);
137 lcfg_set_devname(argv[2]);
143 int jt_lcfg_setup(int argc, char **argv)
145 struct lustre_cfg_bufs bufs;
146 struct lustre_cfg *lcfg;
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]));
156 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
161 for (i = 1; i < argc; i++) {
162 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
165 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
166 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
167 lustre_cfg_free(lcfg);
169 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
170 strerror(rc = errno));
175 int jt_obd_detach(int argc, char **argv)
177 struct lustre_cfg_bufs bufs;
178 struct lustre_cfg *lcfg;
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]));
187 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
192 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
193 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
194 lustre_cfg_free(lcfg);
197 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
198 strerror(rc = errno));
202 int jt_obd_cleanup(int argc, char **argv)
204 struct lustre_cfg_bufs bufs;
205 struct lustre_cfg *lcfg;
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]));
221 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
223 if (argc < 1 || argc > 3)
226 /* we are protected from overflowing our buffer by the argc
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;
235 fprintf(stderr, "unknown option: %s", argv[n]);
241 lustre_cfg_bufs_set_string(&bufs, 1, flags);
244 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
245 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
246 lustre_cfg_free(lcfg);
248 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
249 strerror(rc = errno));
255 int do_add_uuid(char * func, char *uuid, ptl_nid_t nid, int nal)
259 struct lustre_cfg_bufs bufs;
260 struct lustre_cfg *lcfg;
262 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
264 lustre_cfg_bufs_set_string(&bufs, 1, uuid);
266 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
267 lcfg->lcfg_nid = nid;
268 lcfg->lcfg_nal = nal;
270 rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg);
271 lustre_cfg_free(lcfg);
273 fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
278 printf ("Added uuid %s: %s\n", uuid, ptl_nid2str (tmp, nid));
283 int jt_lcfg_add_uuid(int argc, char **argv)
292 if (ptl_parse_nid (&nid, argv[2]) != 0) {
293 fprintf (stderr, "Can't parse NID %s\n", argv[2]);
297 nal = ptl_name2nal(argv[3]);
300 fprintf (stderr, "Can't parse NAL %s\n", argv[3]);
304 return do_add_uuid(argv[0], argv[1], nid, nal);
307 int obd_add_uuid(char *uuid, ptl_nid_t nid, int nal)
309 return do_add_uuid("obd_add_uuid", uuid, nid, nal);
312 int jt_lcfg_del_uuid(int argc, char **argv)
315 struct lustre_cfg_bufs bufs;
316 struct lustre_cfg *lcfg;
319 fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
323 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
324 if (strcmp (argv[1], "_all_"))
325 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
327 lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
328 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
329 lustre_cfg_free(lcfg);
331 fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
338 int jt_lcfg_lov_setup(int argc, char **argv)
340 struct lustre_cfg_bufs bufs;
341 struct lustre_cfg *lcfg;
342 struct lov_desc desc;
346 /* argv: lov_setup <LOV uuid> <stripe count> <stripe size>
347 * <stripe offset> <pattern>
352 if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
354 "error: %s: LOV uuid '%s' longer than "LPSZ" chars\n",
355 jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
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);
363 fprintf(stderr, "error: %s: bad default stripe count '%s'\n",
364 jt_cmdname(argv[0]), argv[2]);
368 desc.ld_default_stripe_size = strtoull(argv[3], &end, 0);
370 fprintf(stderr, "error: %s: bad default stripe size '%s'\n",
371 jt_cmdname(argv[0]), argv[3]);
374 if (desc.ld_default_stripe_size < 4096) {
376 "error: %s: default stripe size "LPU64" too small\n",
377 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
379 } else if ((long)desc.ld_default_stripe_size <
380 desc.ld_default_stripe_size) {
382 "error: %s: default stripe size "LPU64" too large\n",
383 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
387 desc.ld_default_stripe_offset = strtoull(argv[4], &end, 0);
389 fprintf(stderr, "error: %s: bad default stripe offset '%s'\n",
390 jt_cmdname(argv[0]), argv[4]);
394 desc.ld_pattern = strtoul(argv[5], &end, 0);
396 fprintf(stderr, "error: %s: bad stripe pattern '%s'\n",
397 jt_cmdname(argv[0]), argv[5]);
401 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
402 lustre_cfg_bufs_set(&bufs, 1, &desc, sizeof(desc));
404 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
405 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
406 lustre_cfg_free(lcfg);
408 fprintf(stderr, "error: %s: ioctl error: %s\n",
409 jt_cmdname(argv[0]), strerror(rc = errno));
413 int jt_lcfg_lmv_setup(int argc, char **argv)
415 struct lustre_cfg_bufs bufs;
416 struct lustre_cfg *lcfg;
417 struct lmv_desc desc;
418 struct obd_uuid *uuidarray, *ptr;
421 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
425 if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
427 "error: %s: LMV uuid '%s' longer than "LPSZ" chars\n",
428 jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
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);
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.
443 uuidarray = calloc(desc.ld_tgt_count, sizeof(*uuidarray));
445 fprintf(stderr, "error: %s: no memory for %d UUIDs\n",
446 jt_cmdname(argv[0]), desc.ld_tgt_count);
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]);
457 printf(" %s\n", argv[i]);
458 strcpy((char *)ptr, argv[i]);
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);
469 fprintf(stderr, "error: %s: ioctl error: %s\n",
470 jt_cmdname(argv[0]), strerror(rc = errno));
475 int jt_lcfg_lov_modify_tgts(int argc, char **argv)
477 struct lustre_cfg_bufs bufs;
478 struct lustre_cfg *lcfg;
485 /* argv: lov_modify_tgts <op> <LOV name> <OBD uuid> <index> <gen> */
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;
494 fprintf(stderr, "error: %s: bad operation '%s'\n",
495 jt_cmdname(argv[0]), argv[1]);
499 lustre_cfg_bufs_reset(&bufs, argv[2]);
502 if (((index = strlen(argv[3]) + 1)) > sizeof(struct obd_uuid)) {
504 "error: %s: OBD uuid '%s' longer than "LPSZ" chars\n",
505 jt_cmdname(argv[0]), argv[3],
506 sizeof(struct obd_uuid) - 1);
509 lustre_cfg_bufs_set(&bufs, 1, argv[3], index);
511 index = strtoul(argv[4], &end, 0);
513 fprintf(stderr, "error: %s: bad OBD index '%s'\n",
514 jt_cmdname(argv[0]), argv[4]);
517 lustre_cfg_bufs_set(&bufs, 2, argv[4], strlen(argv[4]));
519 gen = strtoul(argv[5], &end, 0);
521 fprintf(stderr, "error: %s: bad OBD generation '%s'\n",
522 jt_cmdname(argv[0]), argv[5]);
525 lustre_cfg_bufs_set(&bufs, 3, argv[5], strlen(argv[5]));
527 lcfg = lustre_cfg_new(cmd, &bufs);
528 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
529 lustre_cfg_free(lcfg);
531 fprintf(stderr, "error: %s: ioctl error: %s\n",
532 jt_cmdname(argv[0]), strerror(rc = errno));
536 int jt_lcfg_mount_option(int argc, char **argv)
539 struct lustre_cfg_bufs bufs;
540 struct lustre_cfg *lcfg;
543 if (argc < 3 || argc > 5)
546 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
548 for (i = 1; i < argc; i++)
549 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
551 lcfg = lustre_cfg_new(LCFG_MOUNTOPT, &bufs);
552 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
553 lustre_cfg_free(lcfg);
555 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
556 strerror(rc = errno));
561 int jt_lcfg_del_mount_option(int argc, char **argv)
564 struct lustre_cfg_bufs bufs;
565 struct lustre_cfg *lcfg;
570 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
573 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
575 lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
576 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
577 lustre_cfg_free(lcfg);
579 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
580 strerror(rc = errno));
585 int jt_lcfg_set_timeout(int argc, char **argv)
588 struct lustre_cfg_bufs bufs;
589 struct lustre_cfg *lcfg;
594 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
595 lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
596 lcfg->lcfg_num = atoi(argv[1]);
598 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
599 lustre_cfg_free(lcfg);
601 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
602 strerror(rc = errno));
608 int jt_lcfg_set_lustre_upcall(int argc, char **argv)
611 struct lustre_cfg_bufs bufs;
612 struct lustre_cfg *lcfg;
617 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
620 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
622 lcfg = lustre_cfg_new(LCFG_SET_UPCALL, &bufs);
623 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
624 lustre_cfg_free(lcfg);
626 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
627 strerror(rc = errno));
632 int jt_lcfg_add_conn(int argc, char **argv)
634 struct lustre_cfg_bufs bufs;
635 struct lustre_cfg *lcfg;
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]));
653 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
655 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
657 lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs);
658 lcfg->lcfg_num = priority;
660 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
661 lustre_cfg_free (lcfg);
663 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
664 strerror(rc = errno));
669 int jt_lcfg_del_conn(int argc, char **argv)
671 struct lustre_cfg_bufs bufs;
672 struct lustre_cfg *lcfg;
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]));
685 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
687 /* connection uuid */
688 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
690 lcfg = lustre_cfg_new(LCFG_DEL_CONN, &bufs);
692 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
693 lustre_cfg_free(lcfg);
695 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
696 strerror(rc = errno));
702 int jt_lcfg_set_security(int argc, char **argv)
704 struct lustre_cfg_bufs bufs;
705 struct lustre_cfg *lcfg;
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]));
718 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
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]);
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]);
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);
741 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
742 lustre_cfg_free(lcfg);
744 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
745 strerror(rc = errno));