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 if (argc != 2 && argc != 3 && argc != 4)
103 lustre_cfg_bufs_reset(&bufs, NULL);
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]);
118 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
119 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
120 lustre_cfg_free(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_bufs bufs;
147 struct lustre_cfg *lcfg;
151 if (lcfg_devname == NULL) {
152 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
153 "device name for config commands.\n",
154 jt_cmdname(argv[0]));
158 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
163 for (i = 1; i < argc; i++) {
164 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
167 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
168 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
169 lustre_cfg_free(lcfg);
171 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
172 strerror(rc = errno));
177 int jt_obd_detach(int argc, char **argv)
179 struct lustre_cfg_bufs bufs;
180 struct lustre_cfg *lcfg;
183 if (lcfg_devname == NULL) {
184 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
185 "device name for config commands.\n",
186 jt_cmdname(argv[0]));
190 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
195 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
196 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
197 lustre_cfg_free(lcfg);
199 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
200 strerror(rc = errno));
205 int jt_obd_cleanup(int argc, char **argv)
207 struct lustre_cfg_bufs bufs;
208 struct lustre_cfg *lcfg;
211 char flags[3] = { 0 };
215 if (lcfg_devname == NULL) {
216 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
217 "device name for config commands.\n",
218 jt_cmdname(argv[0]));
222 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
224 if (argc < 1 || argc > 3)
227 /* we are protected from overflowing our buffer by the argc
230 for (n = 1; n < argc; n++) {
231 if (strcmp(argv[n], "force") == 0) {
232 flags[flag_cnt++] = force;
233 } else if (strcmp(argv[n], "failover") == 0) {
234 flags[flag_cnt++] = failover;
236 fprintf(stderr, "unknown option: %s", argv[n]);
242 lustre_cfg_bufs_set_string(&bufs, 1, flags);
245 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
246 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
247 lustre_cfg_free(lcfg);
249 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
250 strerror(rc = errno));
256 int do_add_uuid(char * func, char *uuid, ptl_nid_t nid, int nal)
260 struct lustre_cfg_bufs bufs;
261 struct lustre_cfg *lcfg;
263 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
265 lustre_cfg_bufs_set_string(&bufs, 1, uuid);
267 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
268 lcfg->lcfg_nid = nid;
269 lcfg->lcfg_nal = nal;
272 fprintf(stderr, "adding\tnal: %d\tnid: %d\tuuid: %s\n",
273 lcfg->lcfg_nid, lcfg->lcfg_nal, uuid);
275 rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg);
276 lustre_cfg_free(lcfg);
278 fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
283 printf ("Added uuid %s: %s\n", uuid, ptl_nid2str (tmp, nid));
287 int jt_lcfg_add_uuid(int argc, char **argv)
296 if (ptl_parse_nid (&nid, argv[2]) != 0) {
297 fprintf (stderr, "Can't parse NID %s\n", argv[2]);
301 nal = ptl_name2nal(argv[3]);
304 fprintf (stderr, "Can't parse NAL %s\n", argv[3]);
308 return do_add_uuid(argv[0], argv[1], nid, nal);
311 int obd_add_uuid(char *uuid, ptl_nid_t nid, int nal)
313 return do_add_uuid("obd_add_uuid", uuid, nid, nal);
316 int jt_lcfg_del_uuid(int argc, char **argv)
319 struct lustre_cfg_bufs bufs;
320 struct lustre_cfg *lcfg;
323 fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
327 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
328 if (strcmp (argv[1], "_all_"))
329 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
331 lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
332 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
333 lustre_cfg_free(lcfg);
335 fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
342 int jt_lcfg_lov_setup(int argc, char **argv)
344 struct lustre_cfg_bufs bufs;
345 struct lustre_cfg *lcfg;
346 struct lov_desc desc;
350 /* argv: lov_setup <LOV uuid> <stripe count> <stripe size>
351 * <stripe offset> <pattern> [ <max tgt index> ]
353 if (argc < 6 || argc > 7)
356 if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
358 "error: %s: LOV uuid '%s' longer than "LPSZ" chars\n",
359 jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
363 memset(&desc, 0, sizeof(desc));
364 obd_str2uuid(&desc.ld_uuid, argv[1]);
365 desc.ld_tgt_count = 0;
366 desc.ld_magic = LOV_DESC_MAGIC;
367 desc.ld_default_stripe_count = strtoul(argv[2], &end, 0);
369 fprintf(stderr, "error: %s: bad default stripe count '%s'\n",
370 jt_cmdname(argv[0]), argv[2]);
374 desc.ld_default_stripe_size = strtoull(argv[3], &end, 0);
376 fprintf(stderr, "error: %s: bad default stripe size '%s'\n",
377 jt_cmdname(argv[0]), argv[3]);
380 if (desc.ld_default_stripe_size < 4096) {
382 "error: %s: default stripe size "LPU64" too small\n",
383 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
385 } else if ((long)desc.ld_default_stripe_size <
386 desc.ld_default_stripe_size) {
388 "error: %s: default stripe size "LPU64" too large\n",
389 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
392 desc.ld_default_stripe_offset = strtoull(argv[4], &end, 0);
394 fprintf(stderr, "error: %s: bad default stripe offset '%s'\n",
395 jt_cmdname(argv[0]), argv[4]);
398 desc.ld_pattern = strtoul(argv[5], &end, 0);
400 fprintf(stderr, "error: %s: bad stripe pattern '%s'\n",
401 jt_cmdname(argv[0]), argv[5]);
406 desc.ld_tgt_count = strtoul(argv[6], &end, 0);
408 fprintf(stderr, "error: %s: bad target count '%s'\n",
409 jt_cmdname(argv[0]), argv[6]);
412 if (desc.ld_default_stripe_count > desc.ld_tgt_count) {
414 "error: %s: default stripe count %u > "
415 "OST count %u\n", jt_cmdname(argv[0]),
416 desc.ld_default_stripe_count,
422 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
423 lustre_cfg_bufs_set(&bufs, 1, &desc, sizeof(desc));
425 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
426 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
427 lustre_cfg_free(lcfg);
429 fprintf(stderr, "error: %s: ioctl error: %s\n",
430 jt_cmdname(argv[0]), strerror(rc = errno));
434 int jt_lcfg_lov_modify_tgts(int argc, char **argv)
436 struct lustre_cfg_bufs bufs;
437 struct lustre_cfg *lcfg;
444 /* argv: lov_modify_tgts <op> <LOV name> <OBD uuid> <index> <gen> */
448 if (!strncmp(argv[1], "add", 4)) {
449 cmd = LCFG_LOV_ADD_OBD;
450 } else if (!strncmp(argv[1], "del", 4)) {
451 cmd = LCFG_LOV_DEL_OBD;
453 fprintf(stderr, "error: %s: bad operation '%s'\n",
454 jt_cmdname(argv[0]), argv[1]);
458 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
460 if (((index = strlen(argv[3]) + 1)) > sizeof(struct obd_uuid)) {
462 "error: %s: OBD uuid '%s' longer than "LPSZ" chars\n",
463 jt_cmdname(argv[0]), argv[3],
464 sizeof(struct obd_uuid) - 1);
467 lustre_cfg_bufs_set(&bufs, 1, argv[3], index);
469 index = strtoul(argv[4], &end, 0);
471 fprintf(stderr, "error: %s: bad OBD index '%s'\n",
472 jt_cmdname(argv[0]), argv[4]);
475 lustre_cfg_bufs_set(&bufs, 2, argv[4], strlen(argv[4]));
477 gen = strtoul(argv[5], &end, 0);
479 fprintf(stderr, "error: %s: bad OBD generation '%s'\n",
480 jt_cmdname(argv[0]), argv[5]);
483 lustre_cfg_bufs_set(&bufs, 3, argv[5], strlen(argv[5]));
485 lcfg = lustre_cfg_new(cmd, &bufs);
486 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
487 lustre_cfg_free(lcfg);
489 fprintf(stderr, "error: %s: ioctl error: %s\n",
490 jt_cmdname(argv[0]), strerror(rc = errno));
497 int jt_lcfg_mount_option(int argc, char **argv)
500 struct lustre_cfg_bufs bufs;
501 struct lustre_cfg *lcfg;
504 if (argc < 3 || argc > 4)
507 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
509 for (i = 1; i < argc; i++)
510 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
512 lcfg = lustre_cfg_new(LCFG_MOUNTOPT, &bufs);
513 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
514 lustre_cfg_free(lcfg);
516 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
517 strerror(rc = errno));
522 int jt_lcfg_del_mount_option(int argc, char **argv)
525 struct lustre_cfg_bufs bufs;
526 struct lustre_cfg *lcfg;
531 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
534 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
536 lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
537 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
538 lustre_cfg_free(lcfg);
540 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
541 strerror(rc = errno));
546 int jt_lcfg_set_timeout(int argc, char **argv)
549 struct lustre_cfg_bufs bufs;
550 struct lustre_cfg *lcfg;
555 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
556 lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
557 lcfg->lcfg_num = atoi(argv[1]);
559 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
560 lustre_cfg_free(lcfg);
562 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
563 strerror(rc = errno));
569 int jt_lcfg_set_lustre_upcall(int argc, char **argv)
572 struct lustre_cfg_bufs bufs;
573 struct lustre_cfg *lcfg;
578 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
581 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
583 lcfg = lustre_cfg_new(LCFG_SET_UPCALL, &bufs);
584 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
585 lustre_cfg_free(lcfg);
587 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
588 strerror(rc = errno));
593 int jt_lcfg_add_conn(int argc, char **argv)
595 struct lustre_cfg_bufs bufs;
596 struct lustre_cfg *lcfg;
607 if (lcfg_devname == NULL) {
608 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
609 "device name for config commands.\n",
610 jt_cmdname(argv[0]));
614 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
616 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
618 lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs);
619 lcfg->lcfg_num = priority;
621 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
622 lustre_cfg_free (lcfg);
624 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
625 strerror(rc = errno));
631 int jt_lcfg_del_conn(int argc, char **argv)
633 struct lustre_cfg_bufs bufs;
634 struct lustre_cfg *lcfg;
640 if (lcfg_devname == NULL) {
641 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
642 "device name for config commands.\n",
643 jt_cmdname(argv[0]));
647 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
649 /* connection uuid */
650 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
652 lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
654 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
655 lustre_cfg_free(lcfg);
657 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
658 strerror(rc = errno));