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\n"
57 "usage: setstripe <filename|dirname> <stripe size> <stripe start> <stripe count>\n"
58 "\tstripe size: Number of bytes in each stripe (0 default)\n"
59 "\tstripe start: OST index of first stripe (-1 default)\n"
60 "\tstripe count: Number of OSTs to stripe over (0 default)"},
61 {"dirstripe", lfs_dirstripe, 0,
62 "To create a new dir with a specific striping pattern.\n"
63 "usage: dirstripe <dirname> <stripe count> [<mds idx list>]\n"
64 "\tstripe count: Number of MDSes to stripe over (0 default)\n"
65 "\tmds idx list: List of MDS servers to contain the dir (not implemented)"},
67 "To list the extended attributes for a given filename or files in a\n"
68 "directory or recursively for all files in a directory tree.\n"
69 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
70 {"getstripe", lfs_getstripe, 0,
71 "To list the striping pattern for given filename.\n"
72 "usage: getstripe <filename>"},
73 {"showfid", lfs_showfid, 0,
74 "To list the fid and store cookie for given filename.\n"
75 "usage: showfid [--quiet | --verbose] [--recursive] <dir|file> ..."},
76 {"check", lfs_check, 0,
77 "Display the status of MDS or OSTs (as specified in the command)\n"
78 "or all the servers (MDS and OSTs).\n"
79 "usage: check <osts|mds|servers>"},
80 {"catinfo", lfs_catinfo, 0,
81 "Show information of specified type logs.\n"
82 "usage: catinfo {keyword} [node name]\n"
83 "\tkeywords are one of followings: config, deletions.\n"
84 "\tnode name must be provided when use keyword config."},
85 {"osts", lfs_osts, 0, "osts"},
86 {"help", Parser_help, 0, "help"},
87 {"exit", Parser_quit, 0, "quit"},
88 {"quit", Parser_quit, 0, "quit"},
93 static int lfs_setstripe(int argc, char **argv)
97 int st_offset, st_count;
103 // get the stripe size
104 st_size = strtoul(argv[2], &end, 0);
106 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
110 // get the stripe offset
111 st_offset = strtoul(argv[3], &end, 0);
113 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
117 // get the stripe count
118 st_count = strtoul(argv[4], &end, 0);
120 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
125 result = llapi_file_create(argv[1], st_size, st_offset, st_count, 0);
127 fprintf(stderr, "error: %s: create stripe file failed\n",
133 static int lfs_dirstripe(int argc, char **argv)
142 // get the stripe size
143 st_count = strtoul(argv[2], &end, 0);
145 fprintf(stderr, "error: %s: bad count '%s'\n",
150 result = op_create_dir(argv[1], st_count);
152 fprintf(stderr, "error: %s: create stripe dir failed\n",
158 static int lfs_find(int argc, char **argv)
160 struct option long_opts[] = {
162 {"quiet", 0, 0, 'q'},
163 {"recursive", 0, 0, 'r'},
164 {"verbose", 0, 0, 'v'},
167 char short_opts[] = "ho:qrv";
168 int quiet, verbose, recursive, c, rc;
169 struct obd_uuid *obduuid = NULL;
172 quiet = verbose = recursive = 0;
173 while ((c = getopt_long(argc, argv, short_opts,
174 long_opts, NULL)) != -1) {
179 "error: %s: only one obduuid allowed",
183 obduuid = (struct obd_uuid *)optarg;
200 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
201 argv[0], argv[optind - 1]);
211 rc = llapi_find(argv[optind], obduuid, recursive, verbose, quiet, 0);
212 } while (++optind < argc && !rc);
215 fprintf(stderr, "error: %s: find failed\n", argv[0]);
219 static int lfs_getstripe(int argc, char **argv)
221 struct obd_uuid *obduuid = NULL;
230 rc = llapi_find(argv[optind], obduuid, 0, 0, 0, 0);
231 } while (++optind < argc && !rc);
234 fprintf(stderr, "error: %s: getstripe failed for %s\n",
240 static int lfs_showfid(int argc, char **argv)
242 struct option long_opts[] = {
243 {"quiet", 0, 0, 'q'},
244 {"recursive", 0, 0, 'r'},
245 {"verbose", 0, 0, 'v'},
248 char short_opts[] = "hqrv";
249 int quiet, verbose, recursive, c, rc;
252 quiet = verbose = recursive = 0;
253 while ((c = getopt_long(argc, argv, short_opts,
254 long_opts, NULL)) != -1) {
271 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
272 argv[0], argv[optind - 1]);
281 rc = llapi_find(argv[optind], NULL, recursive, verbose, quiet, 1);
282 } while (++optind < argc && !rc);
285 fprintf(stderr, "error: %s: find failed\n", argv[0]);
290 static int lfs_osts(int argc, char **argv)
293 struct mntent *mnt = NULL;
294 struct obd_uuid *obduuid = NULL;
300 fp = setmntent(MOUNTED, "r");
303 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
307 while (feof(fp) == 0 && ferror(fp) ==0) {
308 if (llapi_is_lustre_mnttype(mnt->mnt_type)) {
309 rc = llapi_find(mnt->mnt_dir, obduuid, 0, 0, 0, 0);
312 "error: lfs osts failed on %s\n",
323 static int lfs_check(int argc, char **argv)
327 struct mntent *mnt = NULL;
336 obd_types[1] = obd_type1;
337 obd_types[2] = obd_type2;
339 if (strcmp(argv[1], "osts") == 0) {
340 strcpy(obd_types[0], "osc");
341 } else if (strcmp(argv[1], "mds") == 0) {
342 strcpy(obd_types[0], "mdc");
343 } else if (strcmp(argv[1], "servers") == 0) {
345 strcpy(obd_types[0], "osc");
346 strcpy(obd_types[1], "mdc");
348 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
353 fp = setmntent(MOUNTED, "r");
355 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
359 while (feof(fp) == 0 && ferror(fp) ==0) {
360 if (llapi_is_lustre_mnttype(mnt->mnt_type))
367 rc = llapi_target_check(num_types, obd_types, mnt->mnt_dir);
370 fprintf(stderr, "error: %s: %s status failed\n",
377 static int lfs_catinfo(int argc, char **argv)
380 struct mntent *mnt = NULL;
383 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
386 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
389 fp = setmntent(MOUNTED, "r");
391 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
395 while (feof(fp) == 0 && ferror(fp) == 0) {
396 if (llapi_is_lustre_mnttype(mnt->mnt_type))
405 rc = llapi_catinfo(mnt->mnt_dir, argv[1], argv[2]);
407 rc = llapi_catinfo(mnt->mnt_dir, argv[1], NULL);
409 fprintf(stderr, "no lustre_lite mounted.\n");
416 int main(int argc, char **argv)
422 ptl_initialize(argc, argv);
423 if (obd_initialize(argc, argv) < 0)
425 if (dbg_initialize(argc, argv) < 0)
428 Parser_init("lfs > ", cmdlist);
431 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
433 rc = Parser_commands();
436 obd_finalize(argc, argv);