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 <lustre_lib.h>
37 #include <lustre_cfg.h>
38 #include <lustre/lustre_idl.h>
39 #include <lustre_dlm.h>
40 #include <obd.h> /* for struct lov_stripe_md */
42 #include <linux/lustre_build_version.h>
53 #include <lnet/lnetctl.h>
57 static char * lcfg_devname;
59 void lcfg_set_devname(char *name)
63 lcfg_devname = strdup(name);
67 int jt_lcfg_device(int argc, char **argv)
72 printf("current device is %s\n", lcfg_devname? : "not set");
74 } else if (argc != 2) {
80 /* quietly strip the unnecessary '$' */
84 lcfg_set_devname(name);
90 int jt_lcfg_newdev(int argc, char **argv)
95 int jt_lcfg_attach(int argc, char **argv)
97 struct lustre_cfg_bufs bufs;
98 struct lustre_cfg *lcfg;
104 lustre_cfg_bufs_reset(&bufs, NULL);
106 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
107 lustre_cfg_bufs_set_string(&bufs, 0, argv[2]);
108 lustre_cfg_bufs_set_string(&bufs, 2, argv[3]);
110 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
111 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
112 lustre_cfg_free(lcfg);
114 fprintf(stderr, "error: %s: LCFG_ATTACH %s\n",
115 jt_cmdname(argv[0]), strerror(rc = errno));
116 } else if (argc == 3) {
119 lcfg_set_devname(argv[2]);
120 if (strlen(argv[2]) > 128) {
121 printf("Name too long to set environment\n");
124 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
125 rc = setenv(name, argv[1], 1);
127 printf("error setting env variable %s\n", name);
130 lcfg_set_devname(argv[2]);
136 int jt_lcfg_setup(int argc, char **argv)
138 struct lustre_cfg_bufs bufs;
139 struct lustre_cfg *lcfg;
143 if (lcfg_devname == NULL) {
144 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
145 "device name for config commands.\n",
146 jt_cmdname(argv[0]));
150 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
155 for (i = 1; i < argc; i++) {
156 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
159 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
160 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
161 lustre_cfg_free(lcfg);
163 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
164 strerror(rc = errno));
169 int jt_obd_detach(int argc, char **argv)
171 struct lustre_cfg_bufs bufs;
172 struct lustre_cfg *lcfg;
175 if (lcfg_devname == NULL) {
176 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
177 "device name for config commands.\n",
178 jt_cmdname(argv[0]));
182 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
187 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
188 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
189 lustre_cfg_free(lcfg);
191 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
192 strerror(rc = errno));
197 int jt_obd_cleanup(int argc, char **argv)
199 struct lustre_cfg_bufs bufs;
200 struct lustre_cfg *lcfg;
203 char flags[3] = { 0 };
207 if (lcfg_devname == NULL) {
208 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
209 "device name for config commands.\n",
210 jt_cmdname(argv[0]));
214 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
216 if (argc < 1 || argc > 3)
219 /* we are protected from overflowing our buffer by the argc
222 for (n = 1; n < argc; n++) {
223 if (strcmp(argv[n], "force") == 0) {
224 flags[flag_cnt++] = force;
225 } else if (strcmp(argv[n], "failover") == 0) {
226 flags[flag_cnt++] = failover;
228 fprintf(stderr, "unknown option: %s", argv[n]);
234 lustre_cfg_bufs_set_string(&bufs, 1, flags);
237 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
238 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
239 lustre_cfg_free(lcfg);
241 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
242 strerror(rc = errno));
248 int do_add_uuid(char * func, char *uuid, lnet_nid_t nid)
251 struct lustre_cfg_bufs bufs;
252 struct lustre_cfg *lcfg;
254 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
256 lustre_cfg_bufs_set_string(&bufs, 1, uuid);
258 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
259 lcfg->lcfg_nid = nid;
260 /* Poison NAL -- pre 1.4.6 will LASSERT on 0 NAL, this way it
261 doesn't work without crashing (bz 10130) */
262 lcfg->lcfg_nal = 0x5a;
265 fprintf(stderr, "adding\tnid: %d\tuuid: %s\n",
266 lcfg->lcfg_nid, uuid);
268 rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg);
269 lustre_cfg_free(lcfg);
271 fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
276 printf ("Added uuid %s: %s\n", uuid, libcfs_nid2str(nid));
280 int jt_lcfg_add_uuid(int argc, char **argv)
288 nid = libcfs_str2nid(argv[2]);
289 if (nid == LNET_NID_ANY) {
290 fprintf (stderr, "Can't parse NID %s\n", argv[2]);
294 return do_add_uuid(argv[0], argv[1], nid);
297 int obd_add_uuid(char *uuid, lnet_nid_t nid)
299 return do_add_uuid("obd_add_uuid", uuid, nid);
302 int jt_lcfg_del_uuid(int argc, char **argv)
305 struct lustre_cfg_bufs bufs;
306 struct lustre_cfg *lcfg;
309 fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
313 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
314 if (strcmp (argv[1], "_all_"))
315 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
317 lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
318 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
319 lustre_cfg_free(lcfg);
321 fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
328 int jt_lcfg_lov_setup(int argc, char **argv)
330 struct lustre_cfg_bufs bufs;
331 struct lustre_cfg *lcfg;
332 struct lov_desc desc;
336 /* argv: lov_setup <LOV uuid> <stripe count> <stripe size>
337 * <stripe offset> <pattern> [ <max tgt index> ]
339 if (argc < 6 || argc > 7)
342 if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
344 "error: %s: LOV uuid '%s' longer than "LPSZ" chars\n",
345 jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
349 memset(&desc, 0, sizeof(desc));
350 obd_str2uuid(&desc.ld_uuid, argv[1]);
351 desc.ld_tgt_count = 0;
352 desc.ld_magic = LOV_DESC_MAGIC;
353 desc.ld_default_stripe_count = strtoul(argv[2], &end, 0);
355 fprintf(stderr, "error: %s: bad default stripe count '%s'\n",
356 jt_cmdname(argv[0]), argv[2]);
360 desc.ld_default_stripe_size = strtoull(argv[3], &end, 0);
362 fprintf(stderr, "error: %s: bad default stripe size '%s'\n",
363 jt_cmdname(argv[0]), argv[3]);
366 if (desc.ld_default_stripe_size < 4096) {
368 "error: %s: default stripe size "LPU64" smaller than "
370 jt_cmdname(argv[0]), desc.ld_default_stripe_size,
371 LOV_MIN_STRIPE_SIZE);
373 } else if ((long)desc.ld_default_stripe_size <
374 desc.ld_default_stripe_size) {
376 "error: %s: default stripe size "LPU64" too large\n",
377 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
380 desc.ld_default_stripe_offset = strtoull(argv[4], &end, 0);
382 fprintf(stderr, "error: %s: bad default stripe offset '%s'\n",
383 jt_cmdname(argv[0]), argv[4]);
386 desc.ld_pattern = strtoul(argv[5], &end, 0);
388 fprintf(stderr, "error: %s: bad stripe pattern '%s'\n",
389 jt_cmdname(argv[0]), argv[5]);
392 desc.ld_qos_maxage = QOS_DEFAULT_MAXAGE;
395 desc.ld_tgt_count = strtoul(argv[6], &end, 0);
397 fprintf(stderr, "error: %s: bad target count '%s'\n",
398 jt_cmdname(argv[0]), argv[6]);
401 if (desc.ld_default_stripe_count > desc.ld_tgt_count) {
403 "error: %s: default stripe count %u > "
404 "OST count %u\n", jt_cmdname(argv[0]),
405 desc.ld_default_stripe_count,
411 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
412 lustre_cfg_bufs_set(&bufs, 1, &desc, sizeof(desc));
414 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
415 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
416 lustre_cfg_free(lcfg);
418 fprintf(stderr, "error: %s: ioctl error: %s\n",
419 jt_cmdname(argv[0]), strerror(rc = errno));
423 int jt_lcfg_lov_modify_tgts(int argc, char **argv)
425 struct lustre_cfg_bufs bufs;
426 struct lustre_cfg *lcfg;
433 /* argv: lov_modify_tgts <op> <LOV name> <OBD uuid> <index> <gen> */
437 if (!strncmp(argv[1], "add", 4)) {
438 cmd = LCFG_LOV_ADD_OBD;
439 } else if (!strncmp(argv[1], "del", 4)) {
440 cmd = LCFG_LOV_DEL_OBD;
442 fprintf(stderr, "error: %s: bad operation '%s'\n",
443 jt_cmdname(argv[0]), argv[1]);
447 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
449 if (((index = strlen(argv[3]) + 1)) > sizeof(struct obd_uuid)) {
451 "error: %s: OBD uuid '%s' longer than "LPSZ" chars\n",
452 jt_cmdname(argv[0]), argv[3],
453 sizeof(struct obd_uuid) - 1);
456 lustre_cfg_bufs_set(&bufs, 1, argv[3], index);
458 index = strtoul(argv[4], &end, 0);
460 fprintf(stderr, "error: %s: bad OBD index '%s'\n",
461 jt_cmdname(argv[0]), argv[4]);
464 lustre_cfg_bufs_set(&bufs, 2, argv[4], strlen(argv[4]));
466 gen = strtoul(argv[5], &end, 0);
468 fprintf(stderr, "error: %s: bad OBD generation '%s'\n",
469 jt_cmdname(argv[0]), argv[5]);
472 lustre_cfg_bufs_set(&bufs, 3, argv[5], strlen(argv[5]));
474 lcfg = lustre_cfg_new(cmd, &bufs);
475 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
476 lustre_cfg_free(lcfg);
478 fprintf(stderr, "error: %s: ioctl error: %s\n",
479 jt_cmdname(argv[0]), strerror(rc = errno));
486 int jt_lcfg_mount_option(int argc, char **argv)
489 struct lustre_cfg_bufs bufs;
490 struct lustre_cfg *lcfg;
493 if (argc < 3 || argc > 4)
496 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
498 for (i = 1; i < argc; i++)
499 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
501 lcfg = lustre_cfg_new(LCFG_MOUNTOPT, &bufs);
502 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
503 lustre_cfg_free(lcfg);
505 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
506 strerror(rc = errno));
511 int jt_lcfg_del_mount_option(int argc, char **argv)
514 struct lustre_cfg_bufs bufs;
515 struct lustre_cfg *lcfg;
520 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
523 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
525 lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
526 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
527 lustre_cfg_free(lcfg);
529 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
530 strerror(rc = errno));
535 int jt_lcfg_set_timeout(int argc, char **argv)
538 struct lustre_cfg_bufs bufs;
539 struct lustre_cfg *lcfg;
541 fprintf(stderr, "%s has been deprecated. Use conf_param instead.\n"
542 "e.g. conf_param lustre-MDT0000 obd_timeout=50\n",
543 jt_cmdname(argv[0]));
550 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
551 lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
552 lcfg->lcfg_num = atoi(argv[1]);
554 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
555 //rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
557 lustre_cfg_free(lcfg);
559 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
560 strerror(rc = errno));
566 int jt_lcfg_set_lustre_upcall(int argc, char **argv)
569 struct lustre_cfg_bufs bufs;
570 struct lustre_cfg *lcfg;
575 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
578 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
580 lcfg = lustre_cfg_new(LCFG_SET_UPCALL, &bufs);
581 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
582 lustre_cfg_free(lcfg);
584 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
585 strerror(rc = errno));
590 int jt_lcfg_add_conn(int argc, char **argv)
592 struct lustre_cfg_bufs bufs;
593 struct lustre_cfg *lcfg;
604 if (lcfg_devname == NULL) {
605 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
606 "device name for config commands.\n",
607 jt_cmdname(argv[0]));
611 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
613 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
615 lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs);
616 lcfg->lcfg_num = priority;
618 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
619 lustre_cfg_free (lcfg);
621 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
622 strerror(rc = errno));
628 int jt_lcfg_del_conn(int argc, char **argv)
630 struct lustre_cfg_bufs bufs;
631 struct lustre_cfg *lcfg;
637 if (lcfg_devname == NULL) {
638 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
639 "device name for config commands.\n",
640 jt_cmdname(argv[0]));
644 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
646 /* connection uuid */
647 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
649 lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
651 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
652 lustre_cfg_free(lcfg);
654 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
655 strerror(rc = errno));
661 /* Param set locally, directly on target */
662 int jt_lcfg_param(int argc, char **argv)
665 struct lustre_cfg_bufs bufs;
666 struct lustre_cfg *lcfg;
668 if (argc >= LUSTRE_CFG_MAX_BUFCOUNT)
671 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
673 for (i = 1; i < argc; i++) {
674 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
677 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
679 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
680 lustre_cfg_free(lcfg);
682 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
683 strerror(rc = errno));
688 /* Param set in config log on MGS */
689 /* conf_param <cfg_device> key1=value1 [key2=value2...] */
690 int jt_lcfg_mgsparam(int argc, char **argv)
692 int i, rc, index_offset = 0;
693 struct lustre_cfg_bufs bufs;
694 struct lustre_cfg *lcfg;
696 if ((argc >= LUSTRE_CFG_MAX_BUFCOUNT) || (argc <= 1))
699 if (!strchr(argv[1], '=')) {
700 /* Not key=val, assume <cfg_device> */
701 rc = jt_lcfg_device(2, argv);
707 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
709 for (i = 1; i < (argc - index_offset); i++) {
710 lustre_cfg_bufs_set_string(&bufs, i, argv[i + index_offset]);
713 /* We could put other opcodes here. */
714 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
716 rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
717 lustre_cfg_free(lcfg);
719 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
720 strerror(rc = errno));