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/ptlctl.h>
34 #include <liblustre.h>
35 #include <linux/lustre_idl.h>
36 #include <lustre/liblustreapi.h>
37 #include <lustre/lustre_user.h>
43 static int lfs_setstripe(int argc, char **argv);
44 static int lfs_dirstripe(int argc, char **argv);
45 static int lfs_find(int argc, char **argv);
46 static int lfs_getstripe(int argc, char **argv);
47 static int lfs_showfid(int argc, char **argv);
48 static int lfs_osts(int argc, char **argv);
49 static int lfs_check(int argc, char **argv);
50 static int lfs_catinfo(int argc, char **argv);
52 /* all avaialable commands */
53 command_t cmdlist[] = {
54 {"setstripe", lfs_setstripe, 0,
55 "Create a new file with a specific striping pattern or\n"
56 "set the default striping pattern on an existing directory or\n"
57 "delete the default striping pattern from an existing directory\n"
58 "usage: setstripe <filename|dirname> <stripe size> <stripe start> <stripe count>\n"
60 " setstripe -d <dirname>\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)"},
70 "To list the extended attributes for a given filename or files in a\n"
71 "directory or recursively for all files in a directory tree.\n"
72 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
73 {"getstripe", lfs_getstripe, 0,
74 "To list the striping pattern for given filename.\n"
75 "usage: getstripe <filename>"},
76 {"showfid", lfs_showfid, 0,
77 "To list the fid and store cookie for given filename.\n"
78 "usage: showfid [--quiet | --verbose] [--recursive] <dir|file> ..."},
79 {"check", lfs_check, 0,
80 "Display the status of MDS or OSTs (as specified in the command)\n"
81 "or all the servers (MDS and OSTs).\n"
82 "usage: check <osts|mds|servers>"},
83 {"catinfo", lfs_catinfo, 0,
84 "Show information of specified type logs.\n"
85 "usage: catinfo {keyword} [node name]\n"
86 "\tkeywords are one of followings: config, deletions.\n"
87 "\tnode name must be provided when use keyword config."},
88 {"osts", lfs_osts, 0, "osts"},
89 {"help", Parser_help, 0, "help"},
90 {"exit", Parser_quit, 0, "quit"},
91 {"quit", Parser_quit, 0, "quit"},
96 static int lfs_setstripe(int argc, char **argv)
101 int st_offset = -1, st_count = 0;
104 if (argc != 5 && argc != 3)
108 if (strcmp(argv[1], "-d") != 0)
116 // get the stripe size
117 st_size = strtoul(argv[2], &end, 0);
119 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
123 // get the stripe offset
124 st_offset = strtoul(argv[3], &end, 0);
126 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
130 // get the stripe count
131 st_count = strtoul(argv[4], &end, 0);
133 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
139 result = llapi_file_create(fname, st_size, st_offset, st_count, 0);
141 fprintf(stderr, "error: %s: create stripe file failed\n",
147 static int lfs_dirstripe(int argc, char **argv)
156 // get the stripe size
157 st_count = strtoul(argv[2], &end, 0);
159 fprintf(stderr, "error: %s: bad count '%s'\n",
164 result = op_create_dir(argv[1], st_count);
166 fprintf(stderr, "error: %s: create stripe dir failed\n",
172 static int lfs_find(int argc, char **argv)
174 struct option long_opts[] = {
176 {"quiet", 0, 0, 'q'},
177 {"recursive", 0, 0, 'r'},
178 {"verbose", 0, 0, 'v'},
181 char short_opts[] = "ho:qrv";
182 int quiet, verbose, recursive, c, rc;
183 struct obd_uuid *obduuid = NULL;
186 quiet = verbose = recursive = 0;
187 while ((c = getopt_long(argc, argv, short_opts,
188 long_opts, NULL)) != -1) {
193 "error: %s: only one obduuid allowed",
197 obduuid = (struct obd_uuid *)optarg;
214 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
215 argv[0], argv[optind - 1]);
225 rc = llapi_find(argv[optind], obduuid, recursive, verbose, quiet, 0);
226 } while (++optind < argc && !rc);
229 fprintf(stderr, "error: %s: find failed\n", argv[0]);
233 static int lfs_getstripe(int argc, char **argv)
235 struct option long_opts[] = {
236 {"quiet", 0, 0, 'q'},
237 {"verbose", 0, 0, 'v'},
240 char short_opts[] = "qv";
241 int quiet, verbose, recursive, c, rc;
242 struct obd_uuid *obduuid = NULL;
245 quiet = verbose = recursive = 0;
246 while ((c = getopt_long(argc, argv, short_opts,
247 long_opts, NULL)) != -1) {
252 "error: %s: only one obduuid allowed",
256 obduuid = (struct obd_uuid *)optarg;
270 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
271 argv[0], argv[optind - 1]);
281 rc = llapi_find(argv[optind], obduuid, recursive, verbose, quiet, 0);
282 } while (++optind < argc && !rc);
285 fprintf(stderr, "error: %s: getstripe failed for %s\n",
291 static int lfs_showfid(int argc, char **argv)
293 struct option long_opts[] = {
294 {"quiet", 0, 0, 'q'},
295 {"recursive", 0, 0, 'r'},
296 {"verbose", 0, 0, 'v'},
299 char short_opts[] = "hqrv";
300 int quiet, verbose, recursive, c, rc;
303 quiet = verbose = recursive = 0;
304 while ((c = getopt_long(argc, argv, short_opts,
305 long_opts, NULL)) != -1) {
322 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
323 argv[0], argv[optind - 1]);
332 rc = llapi_find(argv[optind], NULL, recursive, verbose, quiet, 1);
333 } while (++optind < argc && !rc);
336 fprintf(stderr, "error: %s: find failed\n", argv[0]);
341 static int lfs_osts(int argc, char **argv)
344 struct mntent *mnt = NULL;
345 struct obd_uuid *obduuid = NULL;
351 fp = setmntent(MOUNTED, "r");
354 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
358 while (feof(fp) == 0 && ferror(fp) ==0) {
359 if (llapi_is_lustre_mnttype(mnt->mnt_type)) {
360 rc = llapi_find(mnt->mnt_dir, obduuid, 0, 0, 0, 0);
363 "error: lfs osts failed on %s\n",
374 static int lfs_check(int argc, char **argv)
378 struct mntent *mnt = NULL;
387 obd_types[0] = obd_type1;
388 obd_types[1] = obd_type2;
390 if (strcmp(argv[1], "osts") == 0) {
391 strcpy(obd_types[0], "osc");
392 } else if (strcmp(argv[1], "mds") == 0) {
393 strcpy(obd_types[0], "mdc");
394 } else if (strcmp(argv[1], "servers") == 0) {
396 strcpy(obd_types[0], "osc");
397 strcpy(obd_types[1], "mdc");
399 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
404 fp = setmntent(MOUNTED, "r");
406 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
410 while (feof(fp) == 0 && ferror(fp) ==0) {
411 if (llapi_is_lustre_mnttype(mnt->mnt_type))
418 rc = llapi_target_check(num_types, obd_types, mnt->mnt_dir);
421 fprintf(stderr, "error: %s: %s status failed\n",
428 static int lfs_catinfo(int argc, char **argv)
431 struct mntent *mnt = NULL;
434 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
437 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
440 fp = setmntent(MOUNTED, "r");
442 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
446 while (feof(fp) == 0 && ferror(fp) == 0) {
447 if (llapi_is_lustre_mnttype(mnt->mnt_type))
456 rc = llapi_catinfo(mnt->mnt_dir, argv[1], argv[2]);
458 rc = llapi_catinfo(mnt->mnt_dir, argv[1], NULL);
460 fprintf(stderr, "no lustre_lite mounted.\n");
467 int main(int argc, char **argv)
473 ptl_initialize(argc, argv);
474 if (obd_initialize(argc, argv) < 0)
476 if (dbg_initialize(argc, argv) < 0)
479 Parser_init("lfs > ", cmdlist);
482 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
484 rc = Parser_commands();
487 obd_finalize(argc, argv);