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_lov_modify_tgts(int argc, char **argv)
415 struct lustre_cfg_bufs bufs;
416 struct lustre_cfg *lcfg;
423 /* argv: lov_modify_tgts <op> <LOV name> <OBD uuid> <index> <gen> */
427 if (!strncmp(argv[1], "add", 4)) {
428 cmd = LCFG_LOV_ADD_OBD;
429 } else if (!strncmp(argv[1], "del", 4)) {
430 cmd = LCFG_LOV_DEL_OBD;
432 fprintf(stderr, "error: %s: bad operation '%s'\n",
433 jt_cmdname(argv[0]), argv[1]);
437 lustre_cfg_bufs_reset(&bufs, argv[2]);
440 if (((index = strlen(argv[3]) + 1)) > sizeof(struct obd_uuid)) {
442 "error: %s: OBD uuid '%s' longer than "LPSZ" chars\n",
443 jt_cmdname(argv[0]), argv[3],
444 sizeof(struct obd_uuid) - 1);
447 lustre_cfg_bufs_set(&bufs, 1, argv[3], index);
449 index = strtoul(argv[4], &end, 0);
451 fprintf(stderr, "error: %s: bad OBD index '%s'\n",
452 jt_cmdname(argv[0]), argv[4]);
455 lustre_cfg_bufs_set(&bufs, 2, argv[4], strlen(argv[4]));
457 gen = strtoul(argv[5], &end, 0);
459 fprintf(stderr, "error: %s: bad OBD generation '%s'\n",
460 jt_cmdname(argv[0]), argv[5]);
463 lustre_cfg_bufs_set(&bufs, 3, argv[5], strlen(argv[5]));
465 lcfg = lustre_cfg_new(cmd, &bufs);
466 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
467 lustre_cfg_free(lcfg);
469 fprintf(stderr, "error: %s: ioctl error: %s\n",
470 jt_cmdname(argv[0]), strerror(rc = errno));
474 int jt_lcfg_lmv_setup(int argc, char **argv)
476 struct lustre_cfg_bufs bufs;
477 struct lustre_cfg *lcfg;
478 struct lmv_desc desc;
481 /* argv: lmv_setup <lmv_uuid> */
486 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
488 if (strlen(argv[1]) > (sizeof(desc.ld_uuid) - 1)) {
490 "error: %s: LMV uuid '%s' longer than "LPSZ" chars\n",
491 jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
495 memset(&desc, 0, sizeof(desc));
496 obd_str2uuid(&desc.ld_uuid, argv[1]);
498 lustre_cfg_bufs_set(&bufs, 1, &desc, sizeof(desc));
499 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
500 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
502 fprintf(stderr, "error: %s: ioctl error: %s\n",
503 jt_cmdname(argv[0]), strerror(rc = errno));
505 lustre_cfg_free(lcfg);
509 int jt_lcfg_lmv_modify_tgts(int argc, char **argv)
511 struct lustre_cfg_bufs bufs;
512 struct lustre_cfg *lcfg;
513 int mdc_uuid_len, rc;
515 /* NOTE: EXTREME care must be taken to always add MDCs in the same
516 * order, or have only additions at the end of the list.
519 /* argv: lmv_modify_tgts add <LMV name> <MDC uuid> */
523 if (strncmp(argv[1], "add", 4) != 0) {
524 fprintf(stderr, "error: %s: bad operation '%s'\n",
525 jt_cmdname(argv[0]), argv[1]);
529 lustre_cfg_bufs_reset(&bufs, argv[2]);
531 if (((mdc_uuid_len = strlen(argv[3]) + 1)) > sizeof(struct obd_uuid)) {
533 "error: %s: MDC uuid '%s' longer than "LPSZ" chars\n",
534 jt_cmdname(argv[0]), argv[3],
535 sizeof(struct obd_uuid) - 1);
539 lustre_cfg_bufs_set(&bufs, 1, argv[3], mdc_uuid_len);
541 lcfg = lustre_cfg_new(LCFG_LMV_ADD_MDC, &bufs);
542 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
543 lustre_cfg_free(lcfg);
545 fprintf(stderr, "error: %s: ioctl error: %s\n",
546 jt_cmdname(argv[0]), strerror(rc = errno));
550 int jt_lcfg_mount_option(int argc, char **argv)
553 struct lustre_cfg_bufs bufs;
554 struct lustre_cfg *lcfg;
557 if (argc < 3 || argc > 5)
560 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
562 for (i = 1; i < argc; i++)
563 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
565 lcfg = lustre_cfg_new(LCFG_MOUNTOPT, &bufs);
566 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
567 lustre_cfg_free(lcfg);
569 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
570 strerror(rc = errno));
575 int jt_lcfg_del_mount_option(int argc, char **argv)
578 struct lustre_cfg_bufs bufs;
579 struct lustre_cfg *lcfg;
584 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
587 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
589 lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
590 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
591 lustre_cfg_free(lcfg);
593 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
594 strerror(rc = errno));
599 int jt_lcfg_set_timeout(int argc, char **argv)
602 struct lustre_cfg_bufs bufs;
603 struct lustre_cfg *lcfg;
608 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
609 lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
610 lcfg->lcfg_num = atoi(argv[1]);
612 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
613 lustre_cfg_free(lcfg);
615 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
616 strerror(rc = errno));
622 int jt_lcfg_set_lustre_upcall(int argc, char **argv)
625 struct lustre_cfg_bufs bufs;
626 struct lustre_cfg *lcfg;
631 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
634 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
636 lcfg = lustre_cfg_new(LCFG_SET_UPCALL, &bufs);
637 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
638 lustre_cfg_free(lcfg);
640 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
641 strerror(rc = errno));
646 int jt_lcfg_add_conn(int argc, char **argv)
648 struct lustre_cfg_bufs bufs;
649 struct lustre_cfg *lcfg;
660 if (lcfg_devname == NULL) {
661 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
662 "device name for config commands.\n",
663 jt_cmdname(argv[0]));
667 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
669 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
671 lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs);
672 lcfg->lcfg_num = priority;
674 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
675 lustre_cfg_free (lcfg);
677 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
678 strerror(rc = errno));
683 int jt_lcfg_del_conn(int argc, char **argv)
685 struct lustre_cfg_bufs bufs;
686 struct lustre_cfg *lcfg;
692 if (lcfg_devname == NULL) {
693 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
694 "device name for config commands.\n",
695 jt_cmdname(argv[0]));
699 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
701 /* connection uuid */
702 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
704 lcfg = lustre_cfg_new(LCFG_DEL_CONN, &bufs);
706 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
707 lustre_cfg_free(lcfg);
709 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
710 strerror(rc = errno));
716 int jt_lcfg_set_security(int argc, char **argv)
718 struct lustre_cfg_bufs bufs;
719 struct lustre_cfg *lcfg;
725 if (lcfg_devname == NULL) {
726 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
727 "device name for config commands.\n",
728 jt_cmdname(argv[0]));
732 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
734 /* currently only used to set on mds */
735 if (strcmp(argv[1], "mds_sec") &&
736 strcmp(argv[1], "oss_sec") &&
737 strcmp(argv[1], "deny_sec")) {
738 fprintf(stderr, "%s: invalid security key %s\n",
739 jt_cmdname(argv[0]), argv[1]);
742 if (strcmp(argv[2], "null") &&
743 strcmp(argv[2], "krb5i") &&
744 strcmp(argv[2], "krb5p")) {
745 fprintf(stderr, "%s: invalid security value %s\n",
746 jt_cmdname(argv[0]), argv[2]);
750 /* connection uuid */
751 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
752 lustre_cfg_bufs_set_string(&bufs, 2, argv[2]);
753 lcfg = lustre_cfg_new(LCFG_SET_SECURITY, &bufs);
755 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
756 lustre_cfg_free(lcfg);
758 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
759 strerror(rc = errno));