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: Robert Read <rread@clusterfs.com>
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include <portals/api-support.h>
33 #include <portals/ptlctl.h>
35 #include <liblustre.h>
36 #include <linux/lustre_idl.h>
41 extern int op_create_file(char *name, long stripe_size, int stripe_offset,
43 extern int op_find(char *path, struct obd_uuid *obduuid, int recursive,
44 int verbose, int quiet);
45 extern int op_check(int type_num, char **obd_type_p, char *dir);
48 static int lfs_setstripe(int argc, char **argv);
49 static int lfs_find(int argc, char **argv);
50 static int lfs_getstripe(int argc, char **argv);
51 static int lfs_osts(int argc, char **argv);
52 static int lfs_check(int argc, char **argv);
54 /* all avaialable commands */
55 command_t cmdlist[] = {
56 {"setstripe", lfs_setstripe, 0,
58 "usage: setstripe <filename> <stripe size> <stripe start> <stripe count>\n"
59 "\tstripe size: Number of bytes in each stripe (0 default)\n"
60 "\tstripe start: OST index of first stripe (-1 default)\n"
61 "\tstripe count: Number of OSTs to stripe over (0 default)"},
64 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
65 {"getstripe", lfs_getstripe, 0,
67 "usage:getstripe <filename>"},
68 {"check", lfs_check, 0,
70 "usage: check <osts|mds|servers>"},
71 {"osts", lfs_osts, 0, "osts"},
72 {"help", Parser_help, 0, "help"},
73 {"exit", Parser_quit, 0, "quit"},
74 {"quit", Parser_quit, 0, "quit"},
79 static int lfs_setstripe(int argc, char **argv)
83 int st_offset, st_count;
89 // get the stripe size
90 st_size = strtoul(argv[2], &end, 0);
92 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
96 // get the stripe offset
97 st_offset = strtoul(argv[3], &end, 0);
99 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
103 // get the stripe count
104 st_count = strtoul(argv[4], &end, 0);
106 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
111 result = op_create_file(argv[1], st_size, st_offset, st_count);
113 fprintf(stderr, "error: %s: create stripe file failed\n",
119 static int lfs_find(int argc, char **argv)
121 struct option long_opts[] = {
123 {"quiet", 0, 0, 'q'},
124 {"recursive", 0, 0, 'r'},
125 {"verbose", 0, 0, 'v'},
128 char short_opts[] = "ho:qrv";
129 int quiet, verbose, recursive, c, rc;
130 struct obd_uuid *obduuid = NULL;
133 quiet = verbose = recursive = 0;
134 while ((c = getopt_long(argc, argv, short_opts,
135 long_opts, NULL)) != -1) {
140 "error: %s: only one obduuid allowed",
144 obduuid = (struct obd_uuid *)optarg;
161 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
162 argv[0], argv[optind - 1]);
172 rc = op_find(argv[optind], obduuid, recursive, verbose, quiet);
173 } while (++optind < argc && !rc);
176 fprintf(stderr, "error: %s: find failed\n", argv[0]);
180 static int lfs_getstripe(int argc, char **argv)
182 struct obd_uuid *obduuid = NULL;
191 rc = op_find(argv[optind], obduuid, 0, 0, 0);
192 } while (++optind < argc && !rc);
195 fprintf(stderr, "error: %s: getstripe failed for %s\n",
201 static int lfs_osts(int argc, char **argv)
204 struct mntent *mnt = NULL;
205 struct obd_uuid *obduuid = NULL;
211 fp = setmntent(MOUNTED, "r");
214 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
218 while (feof(fp) == 0 && ferror(fp) ==0) {
219 if (strcmp(mnt->mnt_type, "lustre_lite") == 0) {
220 rc = op_find(mnt->mnt_dir, obduuid, 0, 0, 0);
222 fprintf(stderr, "error: lfs osts failed for %s\n",
233 static int lfs_check(int argc, char **argv)
237 struct mntent *mnt = NULL;
246 obd_type_p[1]=obd_type1;
247 obd_type_p[2]=obd_type2;
249 if (strcmp(argv[1],"osts")==0) {
250 strcpy(obd_type_p[0],"osc");
251 } else if (strcmp(argv[1],"mds")==0) {
252 strcpy(obd_type_p[0],"mdc");
253 } else if (strcmp(argv[1],"servers")==0) {
255 strcpy(obd_type_p[0],"osc");
256 strcpy(obd_type_p[1],"mdc");
258 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
263 fp = setmntent(MOUNTED, "r");
265 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
269 while (feof(fp) == 0 && ferror(fp) ==0) {
270 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
277 rc = op_check(type_num,obd_type_p,mnt->mnt_dir);
280 fprintf(stderr, "error: %s: %s status failed\n",
287 int main(int argc, char **argv)
293 ptl_initialize(argc, argv);
294 if (obd_initialize(argc, argv) < 0)
296 if (dbg_initialize(argc, argv) < 0)
299 Parser_init("lfs > ", cmdlist);
302 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
304 rc = Parser_commands();
307 obd_finalize(argc, argv);