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 lcfg;
99 LCFG_INIT(lcfg, LCFG_ATTACH, lcfg_devname);
101 if (argc != 2 && argc != 3 && argc != 4)
104 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
105 lcfg.lcfg_inlbuf1 = argv[1];
107 lcfg.lcfg_dev_namelen = strlen(argv[2]) + 1;
108 lcfg.lcfg_dev_name = argv[2];
110 fprintf(stderr, "error: %s: LCFG_ATTACH requires a name\n",
111 jt_cmdname(argv[0]));
116 lcfg.lcfg_inllen2 = strlen(argv[3]) + 1;
117 lcfg.lcfg_inlbuf2 = argv[3];
120 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
122 fprintf(stderr, "error: %s: LCFG_ATTACH %s\n",
123 jt_cmdname(argv[0]), strerror(rc = errno));
124 } else if (argc == 3) {
127 lcfg_set_devname(argv[2]);
128 if (strlen(argv[2]) > 128) {
129 printf("Name too long to set environment\n");
132 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
133 rc = setenv(name, argv[1], 1);
135 printf("error setting env variable %s\n", name);
138 lcfg_set_devname(argv[2]);
144 int jt_lcfg_setup(int argc, char **argv)
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 LCFG_INIT(lcfg, LCFG_SETUP, lcfg_devname);
162 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
163 lcfg.lcfg_inlbuf1 = argv[1];
166 lcfg.lcfg_inllen2 = strlen(argv[2]) + 1;
167 lcfg.lcfg_inlbuf2 = argv[2];
170 lcfg.lcfg_inllen3 = strlen(argv[3]) + 1;
171 lcfg.lcfg_inlbuf3 = argv[3];
174 lcfg.lcfg_inllen4 = strlen(argv[4]) + 1;
175 lcfg.lcfg_inlbuf4 = argv[4];
178 lcfg.lcfg_inllen5 = strlen(argv[5]) + 1;
179 lcfg.lcfg_inlbuf5 = argv[5];
182 lcfg.lcfg_inllen6 = strlen(argv[6]) + 1;
183 lcfg.lcfg_inlbuf6 = argv[6];
185 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
187 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
188 strerror(rc = errno));
193 int jt_obd_detach(int argc, char **argv)
195 struct lustre_cfg lcfg;
198 if (lcfg_devname == NULL) {
199 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
200 "device name for config commands.\n",
201 jt_cmdname(argv[0]));
205 LCFG_INIT(lcfg, LCFG_DETACH, lcfg_devname);
210 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
212 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
213 strerror(rc = errno));
218 int jt_obd_cleanup(int argc, char **argv)
220 struct lustre_cfg lcfg;
227 if (lcfg_devname == NULL) {
228 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
229 "device name for config commands.\n",
230 jt_cmdname(argv[0]));
234 LCFG_INIT(lcfg, LCFG_CLEANUP, lcfg_devname);
236 if (argc < 1 || argc > 3)
239 for (n = 1; n < argc; n++)
240 if (strcmp(argv[n], "force") == 0) {
241 flags[flag_cnt++] = force;
242 } else if (strcmp(argv[n], "failover") == 0) {
243 flags[flag_cnt++] = failover;
245 fprintf(stderr, "unknown option: %s", argv[n]);
249 lcfg.lcfg_inllen1 = flag_cnt;
251 lcfg.lcfg_inlbuf1 = flags;
253 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
255 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
256 strerror(rc = errno));
262 int do_add_uuid(char * func, char *uuid, ptl_nid_t nid, int nal)
266 struct lustre_cfg lcfg;
268 LCFG_INIT(lcfg, LCFG_ADD_UUID, lcfg_devname);
270 lcfg.lcfg_inllen1 = strlen(uuid) + 1;
271 lcfg.lcfg_inlbuf1 = uuid;
274 rc = lcfg_ioctl(func, OBD_DEV_ID, &lcfg);
276 fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
281 printf ("Added uuid %s: %s\n", uuid, ptl_nid2str (tmp, nid));
285 int jt_lcfg_add_uuid(int argc, char **argv)
294 if (ptl_parse_nid (&nid, argv[2]) != 0) {
295 fprintf (stderr, "Can't parse NID %s\n", argv[2]);
299 nal = ptl_name2nal(argv[3]);
302 fprintf (stderr, "Can't parse NAL %s\n", argv[3]);
306 return do_add_uuid(argv[0], argv[1], nid, nal);
309 int obd_add_uuid(char *uuid, ptl_nid_t nid, int nal)
311 return do_add_uuid("obd_add_uuid", uuid, nid, nal);
314 int jt_lcfg_del_uuid(int argc, char **argv)
317 struct lustre_cfg lcfg;
320 fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
324 LCFG_INIT(lcfg, LCFG_DEL_UUID, lcfg_devname);
326 if (strcmp (argv[1], "_all_"))
328 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
329 lcfg.lcfg_inlbuf1 = argv[1];
332 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
334 fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
341 int jt_lcfg_lov_setup(int argc, char **argv)
343 struct lustre_cfg lcfg;
344 struct lov_desc desc;
348 /* argv: lov_setup <LOV uuid> <stripe count> <stripe size>
349 * <stripe offset> <pattern> [ <max tgt index> ]
354 if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
356 "error: %s: LOV uuid '%s' longer than "LPSZ" chars\n",
357 jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
361 memset(&desc, 0, sizeof(desc));
362 obd_str2uuid(&desc.ld_uuid, argv[1]);
363 desc.ld_default_stripe_count = strtoul(argv[2], &end, 0);
365 fprintf(stderr, "error: %s: bad default stripe count '%s'\n",
366 jt_cmdname(argv[0]), argv[2]);
370 desc.ld_default_stripe_size = strtoull(argv[3], &end, 0);
372 fprintf(stderr, "error: %s: bad default stripe size '%s'\n",
373 jt_cmdname(argv[0]), argv[3]);
376 if (desc.ld_default_stripe_size < 4096) {
378 "error: %s: default stripe size "LPU64" too small\n",
379 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
381 } else if ((long)desc.ld_default_stripe_size <
382 desc.ld_default_stripe_size) {
384 "error: %s: default stripe size "LPU64" too large\n",
385 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
388 desc.ld_default_stripe_offset = strtoull(argv[4], &end, 0);
390 fprintf(stderr, "error: %s: bad default stripe offset '%s'\n",
391 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]);
402 desc.ld_tgt_count = argc - 6;
403 if (desc.ld_default_stripe_count > desc.ld_tgt_count) {
405 "error: %s: default stripe count %u > "
406 "OST count %u\n", jt_cmdname(argv[0]),
407 desc.ld_default_stripe_count,
413 LCFG_INIT(lcfg, LCFG_SETUP, lcfg_devname);
415 lcfg.lcfg_inllen1 = sizeof(desc);
416 lcfg.lcfg_inlbuf1 = (char *)&desc;
418 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
420 fprintf(stderr, "error: %s: ioctl error: %s\n",
421 jt_cmdname(argv[0]), strerror(rc = errno));
425 int jt_lcfg_lmv_setup(int argc, char **argv)
427 struct lustre_cfg lcfg;
428 struct lmv_desc desc;
429 struct obd_uuid *uuidarray, *ptr;
432 LCFG_INIT(lcfg, LCFG_SETUP, lcfg_devname);
437 if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
439 "error: %s: LMV uuid '%s' longer than "LPSZ" chars\n",
440 jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
444 memset(&desc, 0, sizeof(desc));
445 obd_str2uuid(&desc.ld_uuid, argv[1]);
446 desc.ld_tgt_count = argc - 2;
447 printf("LMV: %d uuids:\n", desc.ld_tgt_count);
449 /* NOTE: it is possible to overwrite the default striping parameters,
450 * but EXTREME care must be taken when saving the OST UUID list.
451 * It must be EXACTLY the same, or have only additions at the
452 * end of the list, or only overwrite individual OST entries
453 * that are restored from backups of the previous OST.
455 uuidarray = calloc(desc.ld_tgt_count, sizeof(*uuidarray));
457 fprintf(stderr, "error: %s: no memory for %d UUIDs\n",
458 jt_cmdname(argv[0]), desc.ld_tgt_count);
462 for (i = 2, ptr = uuidarray; i < argc; i++, ptr++) {
463 if (strlen(argv[i]) >= sizeof(*ptr)) {
464 fprintf(stderr, "error: %s: arg %d (%s) too long\n",
465 jt_cmdname(argv[0]), i, argv[i]);
469 printf(" %s\n", argv[i]);
470 strcpy((char *)ptr, argv[i]);
473 lcfg.lcfg_inllen1 = sizeof(desc);
474 lcfg.lcfg_inlbuf1 = (char *)&desc;
475 lcfg.lcfg_inllen2 = desc.ld_tgt_count * sizeof(*uuidarray);
476 lcfg.lcfg_inlbuf2 = (char *)uuidarray;
478 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
480 fprintf(stderr, "error: %s: ioctl error: %s\n",
481 jt_cmdname(argv[0]), strerror(rc = errno));
487 int jt_lcfg_lov_modify_tgts(int argc, char **argv)
489 struct lustre_cfg lcfg;
495 /* argv: lov_modify_tgts <op> <LOV name> <OBD uuid> <index> <gen> */
499 if (!strncmp(argv[1], "add", 4)) {
500 LCFG_INIT(lcfg, LCFG_LOV_ADD_OBD, argv[2]);
501 } else if (!strncmp(argv[1], "del", 4)) {
502 LCFG_INIT(lcfg, LCFG_LOV_DEL_OBD, argv[2]);
504 fprintf(stderr, "error: %s: bad operation '%s'\n",
505 jt_cmdname(argv[0]), argv[1]);
509 lcfg.lcfg_inlbuf1 = argv[3];
510 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
511 if (lcfg.lcfg_inllen1 > sizeof(struct obd_uuid)) {
513 "error: %s: OBD uuid '%s' longer than "LPSZ" chars\n",
514 jt_cmdname(argv[0]), argv[3],
515 sizeof(struct obd_uuid) - 1);
519 index = strtoul(argv[4], &end, 0);
521 fprintf(stderr, "error: %s: bad OBD index '%s'\n",
522 jt_cmdname(argv[0]), argv[4]);
525 lcfg.lcfg_inlbuf2 = argv[4];
526 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2);
528 gen = strtoul(argv[5], &end, 0);
530 fprintf(stderr, "error: %s: bad OBD generation '%s'\n",
531 jt_cmdname(argv[0]), argv[5]);
534 lcfg.lcfg_inlbuf3 = argv[5];
535 lcfg.lcfg_inllen3 = strlen(lcfg.lcfg_inlbuf3);
537 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
539 fprintf(stderr, "error: %s: ioctl error: %s\n",
540 jt_cmdname(argv[0]), strerror(rc = errno));
545 int jt_lcfg_mount_option(int argc, char **argv)
548 struct lustre_cfg lcfg;
550 LCFG_INIT(lcfg, LCFG_MOUNTOPT, lcfg_devname);
552 if (argc < 3 || argc > 4)
556 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
557 lcfg.lcfg_inlbuf1 = argv[1];
559 lcfg.lcfg_inllen2 = strlen(argv[2]) + 1;
560 lcfg.lcfg_inlbuf2 = argv[2];
563 lcfg.lcfg_inllen3 = strlen(argv[3]) + 1;
564 lcfg.lcfg_inlbuf3 = argv[3];
566 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
568 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
569 strerror(rc = errno));
575 int jt_lcfg_del_mount_option(int argc, char **argv)
578 struct lustre_cfg lcfg;
580 LCFG_INIT(lcfg, LCFG_DEL_MOUNTOPT, lcfg_devname);
586 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
587 lcfg.lcfg_inlbuf1 = argv[1];
589 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
591 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
592 strerror(rc = errno));
598 int jt_lcfg_set_timeout(int argc, char **argv)
601 struct lustre_cfg lcfg;
603 LCFG_INIT(lcfg, LCFG_SET_TIMEOUT, lcfg_devname);
608 lcfg.lcfg_num = atoi(argv[1]);
610 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
612 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
613 strerror(rc = errno));
620 int jt_lcfg_set_lustre_upcall(int argc, char **argv)
623 struct lustre_cfg lcfg;
625 LCFG_INIT(lcfg, LCFG_SET_UPCALL, lcfg_devname);
631 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
632 lcfg.lcfg_inlbuf1 = argv[1];
634 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
636 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
637 strerror(rc = errno));
642 int jt_lcfg_add_conn(int argc, char **argv)
644 struct lustre_cfg lcfg;
655 if (lcfg_devname == NULL) {
656 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
657 "device name for config commands.\n",
658 jt_cmdname(argv[0]));
662 LCFG_INIT(lcfg, LCFG_ADD_CONN, lcfg_devname);
664 /* connection uuid */
665 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
666 lcfg.lcfg_inlbuf1 = argv[1];
667 lcfg.lcfg_inllen2 = sizeof(int);
668 lcfg.lcfg_inlbuf2 = (char*) &priority;
670 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
672 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
673 strerror(rc = errno));
679 int jt_lcfg_del_conn(int argc, char **argv)
681 struct lustre_cfg lcfg;
687 if (lcfg_devname == NULL) {
688 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
689 "device name for config commands.\n",
690 jt_cmdname(argv[0]));
694 LCFG_INIT(lcfg, LCFG_DEL_CONN, lcfg_devname);
696 /* connection uuid */
697 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
698 lcfg.lcfg_inlbuf1 = argv[1];
700 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
702 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
703 strerror(rc = errno));