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);
46 extern int op_catinfo(char *dir, char *keyword, char *node_name);
49 static int lfs_setstripe(int argc, char **argv);
50 static int lfs_find(int argc, char **argv);
51 static int lfs_getstripe(int argc, char **argv);
52 static int lfs_osts(int argc, char **argv);
53 static int lfs_check(int argc, char **argv);
54 static int lfs_catinfo(int argc, char **argv);
56 /* all avaialable commands */
57 command_t cmdlist[] = {
58 {"setstripe", lfs_setstripe, 0,
60 "usage: setstripe <filename> <stripe size> <stripe start> <stripe count>\n"
61 "\tstripe size: Number of bytes in each stripe (0 default)\n"
62 "\tstripe start: OST index of first stripe (-1 default)\n"
63 "\tstripe count: Number of OSTs to stripe over (0 default)"},
66 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
67 {"getstripe", lfs_getstripe, 0,
69 "usage:getstripe <filename>"},
70 {"check", lfs_check, 0,
72 "usage: check <osts|mds|servers>"},
73 {"catinfo", lfs_catinfo, 0,
74 "Show information of specified type logs.\n"
75 "usage: catinfo <keyword> [node name]"
76 "keywords are one of followings: config, deletions.\n"
77 "client node name must be provided when use keyword config."},
78 {"osts", lfs_osts, 0, "osts"},
79 {"help", Parser_help, 0, "help"},
80 {"exit", Parser_quit, 0, "quit"},
81 {"quit", Parser_quit, 0, "quit"},
86 static int lfs_setstripe(int argc, char **argv)
90 int st_offset, st_count;
96 // get the stripe size
97 st_size = strtoul(argv[2], &end, 0);
99 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
103 // get the stripe offset
104 st_offset = strtoul(argv[3], &end, 0);
106 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
110 // get the stripe count
111 st_count = strtoul(argv[4], &end, 0);
113 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
118 result = op_create_file(argv[1], st_size, st_offset, st_count);
120 fprintf(stderr, "error: %s: create stripe file failed\n",
126 static int lfs_find(int argc, char **argv)
128 struct option long_opts[] = {
130 {"quiet", 0, 0, 'q'},
131 {"recursive", 0, 0, 'r'},
132 {"verbose", 0, 0, 'v'},
135 char short_opts[] = "ho:qrv";
136 int quiet, verbose, recursive, c, rc;
137 struct obd_uuid *obduuid = NULL;
140 quiet = verbose = recursive = 0;
141 while ((c = getopt_long(argc, argv, short_opts,
142 long_opts, NULL)) != -1) {
147 "error: %s: only one obduuid allowed",
151 obduuid = (struct obd_uuid *)optarg;
168 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
169 argv[0], argv[optind - 1]);
179 rc = op_find(argv[optind], obduuid, recursive, verbose, quiet);
180 } while (++optind < argc && !rc);
183 fprintf(stderr, "error: %s: find failed\n", argv[0]);
187 static int lfs_getstripe(int argc, char **argv)
189 struct obd_uuid *obduuid = NULL;
198 rc = op_find(argv[optind], obduuid, 0, 0, 0);
199 } while (++optind < argc && !rc);
202 fprintf(stderr, "error: %s: getstripe failed for %s\n",
208 static int lfs_osts(int argc, char **argv)
211 struct mntent *mnt = NULL;
212 struct obd_uuid *obduuid = NULL;
218 fp = setmntent(MOUNTED, "r");
221 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
225 while (feof(fp) == 0 && ferror(fp) ==0) {
226 if (strcmp(mnt->mnt_type, "lustre_lite") == 0) {
227 rc = op_find(mnt->mnt_dir, obduuid, 0, 0, 0);
229 fprintf(stderr, "error: lfs osts failed for %s\n",
240 static int lfs_check(int argc, char **argv)
244 struct mntent *mnt = NULL;
253 obd_type_p[1]=obd_type1;
254 obd_type_p[2]=obd_type2;
256 if (strcmp(argv[1],"osts")==0) {
257 strcpy(obd_type_p[0],"osc");
258 } else if (strcmp(argv[1],"mds")==0) {
259 strcpy(obd_type_p[0],"mdc");
260 } else if (strcmp(argv[1],"servers")==0) {
262 strcpy(obd_type_p[0],"osc");
263 strcpy(obd_type_p[1],"mdc");
265 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
270 fp = setmntent(MOUNTED, "r");
272 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
276 while (feof(fp) == 0 && ferror(fp) ==0) {
277 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
284 rc = op_check(type_num,obd_type_p,mnt->mnt_dir);
287 fprintf(stderr, "error: %s: %s status failed\n",
294 static int lfs_catinfo(int argc, char **argv)
297 struct mntent *mnt = NULL;
300 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
303 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
306 fp = setmntent(MOUNTED, "r");
308 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
312 while (feof(fp) == 0 && ferror(fp) == 0) {
313 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
322 rc = op_catinfo(mnt->mnt_dir, argv[1], argv[2]);
324 rc = op_catinfo(mnt->mnt_dir, argv[1], NULL);
326 fprintf(stderr, "no lustre_lite mounted.\n");
333 int main(int argc, char **argv)
339 ptl_initialize(argc, argv);
340 if (obd_initialize(argc, argv) < 0)
342 if (dbg_initialize(argc, argv) < 0)
345 Parser_init("lfs > ", cmdlist);
348 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
350 rc = Parser_commands();
353 obd_finalize(argc, argv);