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>
37 #include <linux/lustre_user.h>
42 extern int op_find(char *path, struct obd_uuid *obduuid, int recursive,
43 int verbose, int quiet);
44 extern int op_check(int type_num, char **obd_type_p, char *dir);
45 extern int op_catinfo(char *dir, char *keyword, char *node_name);
48 static int lfs_setstripe(int argc, char **argv);
49 static int lfs_dirstripe(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,
59 "To create a new file with a specific striping pattern.\n"
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)"},
64 {"dirstripe", lfs_dirstripe, 0,
65 "To create a new dir with a specific striping pattern.\n"
66 "usage: dirstripe <dirname> <stripe count> [<mds idx list>]\n"
67 "\tstripe count: Number of MDSes to stripe over (0 default)\n"
68 "\tmds idx list: List of MDS servers to contain the dir (not implemented)"},
71 "To list the extended attributes for a given filename or files in a directory "
72 "or recursively for all files in a directory tree.\n"
73 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
74 {"getstripe", lfs_getstripe, 0,
75 "To list the striping pattern for given filename.\n"
76 "usage:getstripe <filename>"},
77 {"check", lfs_check, 0,
78 "Display the status of MDS or OSTs (as specified in the command) "
79 "or all the servers (MDS and OSTs).\n"
80 "usage: check <osts|mds|servers>"},
81 {"catinfo", lfs_catinfo, 0,
82 "Show information of specified type logs.\n"
83 "usage: catinfo <keyword> [node name]"
84 "keywords are one of followings: config, deletions.\n"
85 "client node name must be provided when use keyword config."},
86 {"osts", lfs_osts, 0, "osts"},
87 {"help", Parser_help, 0, "help"},
88 {"exit", Parser_quit, 0, "quit"},
89 {"quit", Parser_quit, 0, "quit"},
94 static int lfs_setstripe(int argc, char **argv)
98 int st_offset, st_count;
104 // get the stripe size
105 st_size = strtoul(argv[2], &end, 0);
107 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
111 // get the stripe offset
112 st_offset = strtoul(argv[3], &end, 0);
114 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
118 // get the stripe count
119 st_count = strtoul(argv[4], &end, 0);
121 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
126 result = op_create_file(argv[1], st_size, st_offset, st_count);
128 fprintf(stderr, "error: %s: create stripe file failed\n",
134 static int lfs_dirstripe(int argc, char **argv)
143 // get the stripe size
144 st_count = strtoul(argv[2], &end, 0);
146 fprintf(stderr, "error: %s: bad count '%s'\n",
151 result = op_create_dir(argv[1], st_count);
153 fprintf(stderr, "error: %s: create stripe dir failed\n",
159 static int lfs_find(int argc, char **argv)
161 struct option long_opts[] = {
163 {"quiet", 0, 0, 'q'},
164 {"recursive", 0, 0, 'r'},
165 {"verbose", 0, 0, 'v'},
168 char short_opts[] = "ho:qrv";
169 int quiet, verbose, recursive, c, rc;
170 struct obd_uuid *obduuid = NULL;
173 quiet = verbose = recursive = 0;
174 while ((c = getopt_long(argc, argv, short_opts,
175 long_opts, NULL)) != -1) {
180 "error: %s: only one obduuid allowed",
184 obduuid = (struct obd_uuid *)optarg;
201 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
202 argv[0], argv[optind - 1]);
212 rc = op_find(argv[optind], obduuid, recursive, verbose, quiet);
213 } while (++optind < argc && !rc);
216 fprintf(stderr, "error: %s: find failed\n", argv[0]);
220 static int lfs_getstripe(int argc, char **argv)
222 struct obd_uuid *obduuid = NULL;
231 rc = op_find(argv[optind], obduuid, 0, 0, 0);
232 } while (++optind < argc && !rc);
235 fprintf(stderr, "error: %s: getstripe failed for %s\n",
241 static int lfs_osts(int argc, char **argv)
244 struct mntent *mnt = NULL;
245 struct obd_uuid *obduuid = NULL;
251 fp = setmntent(MOUNTED, "r");
254 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
258 while (feof(fp) == 0 && ferror(fp) ==0) {
259 if (strcmp(mnt->mnt_type, "lustre_lite") == 0) {
260 rc = op_find(mnt->mnt_dir, obduuid, 0, 0, 0);
262 fprintf(stderr, "error: lfs osts failed for %s\n",
273 static int lfs_check(int argc, char **argv)
277 struct mntent *mnt = NULL;
286 obd_type_p[1]=obd_type1;
287 obd_type_p[2]=obd_type2;
289 if (strcmp(argv[1],"osts")==0) {
290 strcpy(obd_type_p[0],"osc");
291 } else if (strcmp(argv[1],"mds")==0) {
292 strcpy(obd_type_p[0],"mdc");
293 } else if (strcmp(argv[1],"servers")==0) {
295 strcpy(obd_type_p[0],"osc");
296 strcpy(obd_type_p[1],"mdc");
298 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
303 fp = setmntent(MOUNTED, "r");
305 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
309 while (feof(fp) == 0 && ferror(fp) ==0) {
310 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
317 rc = op_check(type_num,obd_type_p,mnt->mnt_dir);
320 fprintf(stderr, "error: %s: %s status failed\n",
327 static int lfs_catinfo(int argc, char **argv)
330 struct mntent *mnt = NULL;
333 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
336 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
339 fp = setmntent(MOUNTED, "r");
341 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
345 while (feof(fp) == 0 && ferror(fp) == 0) {
346 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
355 rc = op_catinfo(mnt->mnt_dir, argv[1], argv[2]);
357 rc = op_catinfo(mnt->mnt_dir, argv[1], NULL);
359 fprintf(stderr, "no lustre_lite mounted.\n");
366 int main(int argc, char **argv)
372 ptl_initialize(argc, argv);
373 if (obd_initialize(argc, argv) < 0)
375 if (dbg_initialize(argc, argv) < 0)
378 Parser_init("lfs > ", cmdlist);
381 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
383 rc = Parser_commands();
386 obd_finalize(argc, argv);