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_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);
53 static int lfs_catinfo(int argc, char **argv);
55 /* all avaialable commands */
56 command_t cmdlist[] = {
57 {"setstripe", lfs_setstripe, 0,
58 "To create a new file with a specific striping pattern.\n"
59 "usage: setstripe <filename> <stripe size> <stripe start> <stripe count>\n"
60 "\tstripe size: Number of bytes in each stripe (0 default)\n"
61 "\tstripe start: OST index of first stripe (-1 default)\n"
62 "\tstripe count: Number of OSTs to stripe over (0 default)"},
64 "To list the extended attributes for a given filename or files in a directory "
65 "or recursively for all files in a directory tree.\n"
66 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
67 {"getstripe", lfs_getstripe, 0,
68 "To list the striping pattern for given filename.\n"
69 "usage:getstripe <filename>"},
70 {"check", lfs_check, 0,
71 "Display the status of MDS or OSTs (as specified in the command) "
72 "or all the servers (MDS and OSTs).\n"
73 "usage: check <osts|mds|servers>"},
74 {"catinfo", lfs_catinfo, 0,
75 "Show information of specified type logs.\n"
76 "usage: catinfo <keyword> [node name]"
77 "keywords are one of followings: config, deletions.\n"
78 "client node name must be provided when use keyword config."},
79 {"osts", lfs_osts, 0, "osts"},
80 {"help", Parser_help, 0, "help"},
81 {"exit", Parser_quit, 0, "quit"},
82 {"quit", Parser_quit, 0, "quit"},
87 static int lfs_setstripe(int argc, char **argv)
91 int st_offset, st_count;
97 // get the stripe size
98 st_size = strtoul(argv[2], &end, 0);
100 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
104 // get the stripe offset
105 st_offset = strtoul(argv[3], &end, 0);
107 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
111 // get the stripe count
112 st_count = strtoul(argv[4], &end, 0);
114 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
119 result = op_create_file(argv[1], st_size, st_offset, st_count);
121 fprintf(stderr, "error: %s: create stripe file failed\n",
127 static int lfs_find(int argc, char **argv)
129 struct option long_opts[] = {
131 {"quiet", 0, 0, 'q'},
132 {"recursive", 0, 0, 'r'},
133 {"verbose", 0, 0, 'v'},
136 char short_opts[] = "ho:qrv";
137 int quiet, verbose, recursive, c, rc;
138 struct obd_uuid *obduuid = NULL;
141 quiet = verbose = recursive = 0;
142 while ((c = getopt_long(argc, argv, short_opts,
143 long_opts, NULL)) != -1) {
148 "error: %s: only one obduuid allowed",
152 obduuid = (struct obd_uuid *)optarg;
169 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
170 argv[0], argv[optind - 1]);
180 rc = op_find(argv[optind], obduuid, recursive, verbose, quiet);
181 } while (++optind < argc && !rc);
184 fprintf(stderr, "error: %s: find failed\n", argv[0]);
188 static int lfs_getstripe(int argc, char **argv)
190 struct obd_uuid *obduuid = NULL;
199 rc = op_find(argv[optind], obduuid, 0, 0, 0);
200 } while (++optind < argc && !rc);
203 fprintf(stderr, "error: %s: getstripe failed for %s\n",
209 static int lfs_osts(int argc, char **argv)
212 struct mntent *mnt = NULL;
213 struct obd_uuid *obduuid = NULL;
219 fp = setmntent(MOUNTED, "r");
222 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
226 while (feof(fp) == 0 && ferror(fp) ==0) {
227 if (strcmp(mnt->mnt_type, "lustre_lite") == 0) {
228 rc = op_find(mnt->mnt_dir, obduuid, 0, 0, 0);
230 fprintf(stderr, "error: lfs osts failed for %s\n",
241 static int lfs_check(int argc, char **argv)
245 struct mntent *mnt = NULL;
254 obd_type_p[1]=obd_type1;
255 obd_type_p[2]=obd_type2;
257 if (strcmp(argv[1],"osts")==0) {
258 strcpy(obd_type_p[0],"osc");
259 } else if (strcmp(argv[1],"mds")==0) {
260 strcpy(obd_type_p[0],"mdc");
261 } else if (strcmp(argv[1],"servers")==0) {
263 strcpy(obd_type_p[0],"osc");
264 strcpy(obd_type_p[1],"mdc");
266 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
271 fp = setmntent(MOUNTED, "r");
273 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
277 while (feof(fp) == 0 && ferror(fp) ==0) {
278 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
285 rc = op_check(type_num,obd_type_p,mnt->mnt_dir);
288 fprintf(stderr, "error: %s: %s status failed\n",
295 static int lfs_catinfo(int argc, char **argv)
298 struct mntent *mnt = NULL;
301 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
304 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
307 fp = setmntent(MOUNTED, "r");
309 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
313 while (feof(fp) == 0 && ferror(fp) == 0) {
314 if (strcmp(mnt->mnt_type, "lustre_lite") == 0)
323 rc = op_catinfo(mnt->mnt_dir, argv[1], argv[2]);
325 rc = op_catinfo(mnt->mnt_dir, argv[1], NULL);
327 fprintf(stderr, "no lustre_lite mounted.\n");
334 int main(int argc, char **argv)
340 ptl_initialize(argc, argv);
341 if (obd_initialize(argc, argv) < 0)
343 if (dbg_initialize(argc, argv) < 0)
346 Parser_init("lfs > ", cmdlist);
349 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
351 rc = Parser_commands();
354 obd_finalize(argc, argv);