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,
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)"},
65 "To list the extended attributes for a given filename or files in a directory "
66 "or recursively for all files in a directory tree.\n"
67 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
68 {"getstripe", lfs_getstripe, 0,
69 "To list the striping pattern for given filename.\n"
70 "usage:getstripe <filename>"},
71 {"check", lfs_check, 0,
72 "Display the status of MDS or OSTs (as specified in the command) "
73 "or all the servers (MDS and OSTs).\n"
74 "usage: check <osts|mds|servers>"},
75 {"catinfo", lfs_catinfo, 0,
76 "Show information of specified type logs.\n"
77 "usage: catinfo <keyword> [node name]"
78 "keywords are one of followings: config, deletions.\n"
79 "client node name must be provided when use keyword config."},
80 {"osts", lfs_osts, 0, "osts"},
81 {"help", Parser_help, 0, "help"},
82 {"exit", Parser_quit, 0, "quit"},
83 {"quit", Parser_quit, 0, "quit"},
88 static int lfs_setstripe(int argc, char **argv)
92 int st_offset, st_count;
98 // get the stripe size
99 st_size = strtoul(argv[2], &end, 0);
101 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
105 // get the stripe offset
106 st_offset = strtoul(argv[3], &end, 0);
108 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
112 // get the stripe count
113 st_count = strtoul(argv[4], &end, 0);
115 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
120 result = op_create_file(argv[1], st_size, st_offset, st_count);
122 fprintf(stderr, "error: %s: create stripe file failed\n",
128 static int lfs_find(int argc, char **argv)
130 struct option long_opts[] = {
132 {"quiet", 0, 0, 'q'},
133 {"recursive", 0, 0, 'r'},
134 {"verbose", 0, 0, 'v'},
137 char short_opts[] = "ho:qrv";
138 int quiet, verbose, recursive, c, rc;
139 struct obd_uuid *obduuid = NULL;
142 quiet = verbose = recursive = 0;
143 while ((c = getopt_long(argc, argv, short_opts,
144 long_opts, NULL)) != -1) {
149 "error: %s: only one obduuid allowed",
153 obduuid = (struct obd_uuid *)optarg;
170 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
171 argv[0], argv[optind - 1]);
181 rc = op_find(argv[optind], obduuid, recursive, verbose, quiet);
182 } while (++optind < argc && !rc);
185 fprintf(stderr, "error: %s: find failed\n", argv[0]);
189 static int lfs_getstripe(int argc, char **argv)
191 struct obd_uuid *obduuid = NULL;
200 rc = op_find(argv[optind], obduuid, 0, 0, 0);
201 } while (++optind < argc && !rc);
204 fprintf(stderr, "error: %s: getstripe failed for %s\n",
210 static int lfs_osts(int argc, char **argv)
213 struct mntent *mnt = NULL;
214 struct obd_uuid *obduuid = NULL;
220 fp = setmntent(MOUNTED, "r");
223 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
227 while (feof(fp) == 0 && ferror(fp) ==0) {
228 if (strcmp(mnt->mnt_type, "lustre_lite") == 0) {
229 rc = op_find(mnt->mnt_dir, obduuid, 0, 0, 0);
231 fprintf(stderr, "error: lfs osts failed for %s\n",
242 static int lfs_check(int argc, char **argv)
246 struct mntent *mnt = NULL;
255 obd_type_p[1]=obd_type1;
256 obd_type_p[2]=obd_type2;
258 if (strcmp(argv[1],"osts")==0) {
259 strcpy(obd_type_p[0],"osc");
260 } else if (strcmp(argv[1],"mds")==0) {
261 strcpy(obd_type_p[0],"mdc");
262 } else if (strcmp(argv[1],"servers")==0) {
264 strcpy(obd_type_p[0],"osc");
265 strcpy(obd_type_p[1],"mdc");
267 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
272 fp = setmntent(MOUNTED, "r");
274 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
278 while (feof(fp) == 0 && ferror(fp) ==0) {
279 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
286 rc = op_check(type_num,obd_type_p,mnt->mnt_dir);
289 fprintf(stderr, "error: %s: %s status failed\n",
296 static int lfs_catinfo(int argc, char **argv)
299 struct mntent *mnt = NULL;
302 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
305 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
308 fp = setmntent(MOUNTED, "r");
310 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
314 while (feof(fp) == 0 && ferror(fp) == 0) {
315 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
324 rc = op_catinfo(mnt->mnt_dir, argv[1], argv[2]);
326 rc = op_catinfo(mnt->mnt_dir, argv[1], NULL);
328 fprintf(stderr, "no lustre_lite mounted.\n");
335 int main(int argc, char **argv)
341 ptl_initialize(argc, argv);
342 if (obd_initialize(argc, argv) < 0)
344 if (dbg_initialize(argc, argv) < 0)
347 Parser_init("lfs > ", cmdlist);
350 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
352 rc = Parser_commands();
355 obd_finalize(argc, argv);