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_osts(int argc, char **argv);
48 static int lfs_check(int argc, char **argv);
49 static int lfs_catinfo(int argc, char **argv);
51 /* all avaialable commands */
52 command_t cmdlist[] = {
53 {"setstripe", lfs_setstripe, 0,
54 "Create a new file with a specific striping pattern or\n"
55 "Set the default striping pattern on an existing directory\n"
56 "usage: setstripe <filename|dirname> <stripe size> <stripe start> <stripe count>\n"
57 "\tstripe size: Number of bytes in each stripe (0 default)\n"
58 "\tstripe start: OST index of first stripe (-1 default)\n"
59 "\tstripe count: Number of OSTs to stripe over (0 default)"},
60 {"dirstripe", lfs_dirstripe, 0,
61 "To create a new dir with a specific striping pattern.\n"
62 "usage: dirstripe <dirname> <stripe count> [<mds idx list>]\n"
63 "\tstripe count: Number of MDSes to stripe over (0 default)\n"
64 "\tmds idx list: List of MDS servers to contain the dir (not implemented)"},
66 "To list the extended attributes for a given filename or files in a\n"
67 "directory or recursively for all files in a directory tree.\n"
68 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
69 {"getstripe", lfs_getstripe, 0,
70 "To list the striping pattern for given filename.\n"
71 "usage:getstripe <filename>"},
72 {"check", lfs_check, 0,
73 "Display the status of MDS or OSTs (as specified in the command)\n"
74 "or all the servers (MDS and OSTs).\n"
75 "usage: check <osts|mds|servers>"},
76 {"catinfo", lfs_catinfo, 0,
77 "Show information of specified type logs.\n"
78 "usage: catinfo {keyword} [node name]\n"
79 "\tkeywords are one of followings: config, deletions.\n"
80 "\tnode name must be provided when use keyword config."},
81 {"osts", lfs_osts, 0, "osts"},
82 {"help", Parser_help, 0, "help"},
83 {"exit", Parser_quit, 0, "quit"},
84 {"quit", Parser_quit, 0, "quit"},
89 static int lfs_setstripe(int argc, char **argv)
93 int st_offset, st_count;
99 // get the stripe size
100 st_size = strtoul(argv[2], &end, 0);
102 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
106 // get the stripe offset
107 st_offset = strtoul(argv[3], &end, 0);
109 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
113 // get the stripe count
114 st_count = strtoul(argv[4], &end, 0);
116 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
121 result = llapi_file_create(argv[1], st_size, st_offset, st_count, 0);
123 fprintf(stderr, "error: %s: create stripe file failed\n",
129 static int lfs_dirstripe(int argc, char **argv)
138 // get the stripe size
139 st_count = strtoul(argv[2], &end, 0);
141 fprintf(stderr, "error: %s: bad count '%s'\n",
146 result = op_create_dir(argv[1], st_count);
148 fprintf(stderr, "error: %s: create stripe dir failed\n",
154 static int lfs_find(int argc, char **argv)
156 struct option long_opts[] = {
158 {"quiet", 0, 0, 'q'},
159 {"recursive", 0, 0, 'r'},
160 {"verbose", 0, 0, 'v'},
163 char short_opts[] = "ho:qrv";
164 int quiet, verbose, recursive, c, rc;
165 struct obd_uuid *obduuid = NULL;
168 quiet = verbose = recursive = 0;
169 while ((c = getopt_long(argc, argv, short_opts,
170 long_opts, NULL)) != -1) {
175 "error: %s: only one obduuid allowed",
179 obduuid = (struct obd_uuid *)optarg;
196 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
197 argv[0], argv[optind - 1]);
207 rc = llapi_find(argv[optind], obduuid, recursive,verbose,quiet);
208 } while (++optind < argc && !rc);
211 fprintf(stderr, "error: %s: find failed\n", argv[0]);
215 static int lfs_getstripe(int argc, char **argv)
217 struct obd_uuid *obduuid = NULL;
226 rc = llapi_find(argv[optind], obduuid, 0, 0, 0);
227 } while (++optind < argc && !rc);
230 fprintf(stderr, "error: %s: getstripe failed for %s\n",
236 static int lfs_osts(int argc, char **argv)
239 struct mntent *mnt = NULL;
240 struct obd_uuid *obduuid = NULL;
246 fp = setmntent(MOUNTED, "r");
249 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
253 while (feof(fp) == 0 && ferror(fp) ==0) {
254 if (llapi_is_lustre_mnttype(mnt->mnt_type)) {
255 rc = llapi_find(mnt->mnt_dir, obduuid, 0, 0, 0);
258 "error: lfs osts failed on %s\n",
269 static int lfs_check(int argc, char **argv)
273 struct mntent *mnt = NULL;
282 obd_types[1] = obd_type1;
283 obd_types[2] = obd_type2;
285 if (strcmp(argv[1], "osts") == 0) {
286 strcpy(obd_types[0], "osc");
287 } else if (strcmp(argv[1], "mds") == 0) {
288 strcpy(obd_types[0], "mdc");
289 } else if (strcmp(argv[1], "servers") == 0) {
291 strcpy(obd_types[0], "osc");
292 strcpy(obd_types[1], "mdc");
294 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
299 fp = setmntent(MOUNTED, "r");
301 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
305 while (feof(fp) == 0 && ferror(fp) ==0) {
306 if (llapi_is_lustre_mnttype(mnt->mnt_type))
313 rc = llapi_target_check(num_types, obd_types, mnt->mnt_dir);
316 fprintf(stderr, "error: %s: %s status failed\n",
323 static int lfs_catinfo(int argc, char **argv)
326 struct mntent *mnt = NULL;
329 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
332 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
335 fp = setmntent(MOUNTED, "r");
337 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
341 while (feof(fp) == 0 && ferror(fp) == 0) {
342 if (llapi_is_lustre_mnttype(mnt->mnt_type))
351 rc = llapi_catinfo(mnt->mnt_dir, argv[1], argv[2]);
353 rc = llapi_catinfo(mnt->mnt_dir, argv[1], NULL);
355 fprintf(stderr, "no lustre_lite mounted.\n");
362 int main(int argc, char **argv)
368 ptl_initialize(argc, argv);
369 if (obd_initialize(argc, argv) < 0)
371 if (dbg_initialize(argc, argv) < 0)
374 Parser_init("lfs > ", cmdlist);
377 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
379 rc = Parser_commands();
382 obd_finalize(argc, argv);