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 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
180 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
181 strerror(rc = errno));
186 int jt_obd_detach(int argc, char **argv)
188 struct lustre_cfg lcfg;
191 if (lcfg_devname == NULL) {
192 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
193 "device name for config commands.\n",
194 jt_cmdname(argv[0]));
198 LCFG_INIT(lcfg, LCFG_DETACH, lcfg_devname);
203 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
205 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
206 strerror(rc = errno));
211 int jt_obd_cleanup(int argc, char **argv)
213 struct lustre_cfg lcfg;
220 if (lcfg_devname == NULL) {
221 fprintf(stderr, "%s: please use 'cfg_device name' to set the "
222 "device name for config commands.\n",
223 jt_cmdname(argv[0]));
227 LCFG_INIT(lcfg, LCFG_CLEANUP, lcfg_devname);
229 if (argc < 1 || argc > 3)
232 for (n = 1; n < argc; n++)
233 if (strcmp(argv[n], "force") == 0) {
234 flags[flag_cnt++] = force;
235 } else if (strcmp(argv[n], "failover") == 0) {
236 flags[flag_cnt++] = failover;
238 fprintf(stderr, "unknown option: %s", argv[n]);
242 lcfg.lcfg_inllen1 = flag_cnt;
244 lcfg.lcfg_inlbuf1 = flags;
246 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &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 lcfg;
261 LCFG_INIT(lcfg, LCFG_ADD_UUID, lcfg_devname);
263 lcfg.lcfg_inllen1 = strlen(uuid) + 1;
264 lcfg.lcfg_inlbuf1 = uuid;
267 rc = lcfg_ioctl(func, OBD_DEV_ID, &lcfg);
269 fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
274 printf ("Added uuid %s: %s\n", uuid, ptl_nid2str (tmp, nid));
278 int jt_lcfg_add_uuid(int argc, char **argv)
287 if (ptl_parse_nid (&nid, argv[2]) != 0) {
288 fprintf (stderr, "Can't parse NID %s\n", argv[2]);
292 nal = ptl_name2nal(argv[3]);
295 fprintf (stderr, "Can't parse NAL %s\n", argv[3]);
299 return do_add_uuid(argv[0], argv[1], nid, nal);
302 int obd_add_uuid(char *uuid, ptl_nid_t nid, int nal)
304 return do_add_uuid("obd_add_uuid", uuid, nid, nal);
307 int jt_lcfg_del_uuid(int argc, char **argv)
310 struct lustre_cfg lcfg;
313 fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
317 LCFG_INIT(lcfg, LCFG_DEL_UUID, lcfg_devname);
319 if (strcmp (argv[1], "_all_"))
321 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
322 lcfg.lcfg_inlbuf1 = argv[1];
325 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
327 fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
334 int jt_lcfg_lov_setup(int argc, char **argv)
336 struct lustre_cfg lcfg;
337 struct lov_desc desc;
338 struct obd_uuid *uuidarray, *ptr;
342 LCFG_INIT(lcfg, LCFG_SETUP, lcfg_devname);
347 if (strlen(argv[1]) > sizeof(desc.ld_uuid) - 1) {
349 "error: %s: LOV uuid '%s' longer than "LPSZ" chars\n",
350 jt_cmdname(argv[0]), argv[1], sizeof(desc.ld_uuid) - 1);
354 memset(&desc, 0, sizeof(desc));
355 obd_str2uuid(&desc.ld_uuid, argv[1]);
356 desc.ld_tgt_count = argc - 6;
357 desc.ld_default_stripe_count = strtoul(argv[2], &end, 0);
359 fprintf(stderr, "error: %s: bad default stripe count '%s'\n",
360 jt_cmdname(argv[0]), argv[2]);
363 if (desc.ld_default_stripe_count > desc.ld_tgt_count) {
365 "error: %s: default stripe count %u > OST count %u\n",
366 jt_cmdname(argv[0]), desc.ld_default_stripe_count,
371 desc.ld_default_stripe_size = strtoull(argv[3], &end, 0);
373 fprintf(stderr, "error: %s: bad default stripe size '%s'\n",
374 jt_cmdname(argv[0]), argv[3]);
377 if (desc.ld_default_stripe_size < 4096) {
379 "error: %s: default stripe size "LPU64" too small\n",
380 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
382 } else if ((long)desc.ld_default_stripe_size <
383 desc.ld_default_stripe_size) {
385 "error: %s: default stripe size "LPU64" too large\n",
386 jt_cmdname(argv[0]), desc.ld_default_stripe_size);
389 desc.ld_default_stripe_offset = strtoull(argv[4], &end, 0);
391 fprintf(stderr, "error: %s: bad default stripe offset '%s'\n",
392 jt_cmdname(argv[0]), argv[4]);
395 desc.ld_pattern = strtoul(argv[5], &end, 0);
397 fprintf(stderr, "error: %s: bad stripe pattern '%s'\n",
398 jt_cmdname(argv[0]), argv[5]);
402 /* NOTE: it is possible to overwrite the default striping parameters,
403 * but EXTREME care must be taken when saving the OST UUID list.
404 * It must be EXACTLY the same, or have only additions at the
405 * end of the list, or only overwrite individual OST entries
406 * that are restored from backups of the previous OST.
408 uuidarray = calloc(desc.ld_tgt_count, sizeof(*uuidarray));
410 fprintf(stderr, "error: %s: no memory for %d UUIDs\n",
411 jt_cmdname(argv[0]), desc.ld_tgt_count);
415 for (i = 6, ptr = uuidarray; i < argc; i++, ptr++) {
416 if (strlen(argv[i]) >= sizeof(*ptr)) {
417 fprintf(stderr, "error: %s: arg %d (%s) too long\n",
418 jt_cmdname(argv[0]), i, argv[i]);
422 strcpy((char *)ptr, argv[i]);
425 lcfg.lcfg_inllen1 = sizeof(desc);
426 lcfg.lcfg_inlbuf1 = (char *)&desc;
427 lcfg.lcfg_inllen2 = desc.ld_tgt_count * sizeof(*uuidarray);
428 lcfg.lcfg_inlbuf2 = (char *)uuidarray;
430 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
432 fprintf(stderr, "error: %s: ioctl error: %s\n",
433 jt_cmdname(argv[0]), strerror(rc = errno));
439 int jt_lcfg_mount_option(int argc, char **argv)
442 struct lustre_cfg lcfg;
444 LCFG_INIT(lcfg, LCFG_MOUNTOPT, lcfg_devname);
446 if (argc < 3 || argc > 4)
450 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
451 lcfg.lcfg_inlbuf1 = argv[1];
453 lcfg.lcfg_inllen2 = strlen(argv[2]) + 1;
454 lcfg.lcfg_inlbuf2 = argv[2];
457 lcfg.lcfg_inllen3 = strlen(argv[3]) + 1;
458 lcfg.lcfg_inlbuf3 = argv[3];
460 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
462 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
463 strerror(rc = errno));
469 int jt_lcfg_del_mount_option(int argc, char **argv)
472 struct lustre_cfg lcfg;
474 LCFG_INIT(lcfg, LCFG_DEL_MOUNTOPT, lcfg_devname);
480 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
481 lcfg.lcfg_inlbuf1 = argv[1];
483 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
485 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
486 strerror(rc = errno));
492 int jt_lcfg_set_timeout(int argc, char **argv)
495 struct lustre_cfg lcfg;
497 LCFG_INIT(lcfg, LCFG_SET_TIMEOUT, lcfg_devname);
502 lcfg.lcfg_num = atoi(argv[1]);
504 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
506 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
507 strerror(rc = errno));
514 int jt_lcfg_set_lustre_upcall(int argc, char **argv)
517 struct lustre_cfg lcfg;
519 LCFG_INIT(lcfg, LCFG_SET_UPCALL, lcfg_devname);
525 lcfg.lcfg_inllen1 = strlen(argv[1]) + 1;
526 lcfg.lcfg_inlbuf1 = argv[1];
528 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, &lcfg);
530 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
531 strerror(rc = errno));