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 <lustre/liblustreapi.h>
38 #include <lustre/lustre_user.h>
43 unsigned int portal_subsystem_debug = 0;
46 static int lfs_setstripe(int argc, char **argv);
47 static int lfs_find(int argc, char **argv);
48 static int lfs_getstripe(int argc, char **argv);
49 static int lfs_osts(int argc, char **argv);
50 static int lfs_check(int argc, char **argv);
51 static int lfs_catinfo(int argc, char **argv);
53 /* all avaialable commands */
54 command_t cmdlist[] = {
55 {"setstripe", lfs_setstripe, 0,
56 "Create a new file with a specific striping pattern or\n"
57 "Set the default striping pattern on an existing directory\n"
58 "usage: setstripe <filename|dirname> <stripe size> <stripe start> <stripe count>\n"
59 "\tstripe size: Number of bytes in each stripe (0 default)\n"
60 "\tstripe start: OST index of first stripe (-1 default)\n"
61 "\tstripe count: Number of OSTs to stripe over (0 default, -1 all)"},
63 "To list the extended attributes for a given filename or files in a\n"
64 "directory or recursively for all files in a directory tree.\n"
65 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
66 {"getstripe", lfs_getstripe, 0,
67 "To list the striping pattern for given filename.\n"
68 "usage:getstripe <filename>"},
69 {"check", lfs_check, 0,
70 "Display the status of MDS or OSTs (as specified in the command)\n"
71 "or all the servers (MDS and OSTs).\n"
72 "usage: check <osts|mds|servers>"},
73 {"catinfo", lfs_catinfo, 0,
74 "Show information of specified type logs.\n"
75 "usage: catinfo {keyword} [node name]\n"
76 "\tkeywords are one of followings: config, deletions.\n"
77 "\tnode name must be provided when use keyword config."},
78 {"osts", lfs_osts, 0, "osts"},
79 {"help", Parser_help, 0, "help"},
80 {"exit", Parser_quit, 0, "quit"},
81 {"quit", Parser_quit, 0, "quit"},
86 static int lfs_setstripe(int argc, char **argv)
90 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 /* 64 KB is the largest common page size I'm aware of (on ia64), but
105 * check the local page size just in case. */
107 if (getpagesize() > page_size) {
108 fprintf(stderr, "WARNING: your page size (%d) is larger than "
109 "expected.\n", getpagesize());
110 page_size = getpagesize();
112 if (st_size % page_size) {
113 fprintf(stderr, "FATAL: stripe_size must be an even multiple "
114 "of %d bytes.\n", page_size);
118 // get the stripe offset
119 st_offset = strtoul(argv[3], &end, 0);
121 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
125 // get the stripe count
126 st_count = strtoul(argv[4], &end, 0);
128 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
133 result = llapi_file_create(argv[1], st_size, st_offset, st_count, 0);
135 fprintf(stderr, "error: %s: create stripe file failed\n",
141 static int lfs_find(int argc, char **argv)
143 struct option long_opts[] = {
145 {"quiet", 0, 0, 'q'},
146 {"recursive", 0, 0, 'r'},
147 {"verbose", 0, 0, 'v'},
150 char short_opts[] = "ho:qrv";
151 int quiet, verbose, recursive, c, rc;
152 struct obd_uuid *obduuid = NULL;
155 quiet = verbose = recursive = 0;
156 while ((c = getopt_long(argc, argv, short_opts,
157 long_opts, NULL)) != -1) {
162 "error: %s: only one obduuid allowed",
166 obduuid = (struct obd_uuid *)optarg;
183 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
184 argv[0], argv[optind - 1]);
194 rc = llapi_find(argv[optind], obduuid, recursive,verbose,quiet);
195 } while (++optind < argc && !rc);
198 fprintf(stderr, "error: %s: find failed\n", argv[0]);
202 static int lfs_getstripe(int argc, char **argv)
204 struct option long_opts[] = {
205 {"quiet", 0, 0, 'q'},
206 {"verbose", 0, 0, 'v'},
209 char short_opts[] = "qv";
210 int quiet, verbose, recursive, c, rc;
211 struct obd_uuid *obduuid = NULL;
214 quiet = verbose = recursive = 0;
215 while ((c = getopt_long(argc, argv, short_opts,
216 long_opts, NULL)) != -1) {
221 "error: %s: only one obduuid allowed",
225 obduuid = (struct obd_uuid *)optarg;
239 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
240 argv[0], argv[optind - 1]);
250 rc = llapi_find(argv[optind], obduuid, recursive,verbose,quiet);
251 } while (++optind < argc && !rc);
254 fprintf(stderr, "error: %s: getstripe failed for %s\n",
260 static int lfs_osts(int argc, char **argv)
263 struct mntent *mnt = NULL;
264 struct obd_uuid *obduuid = NULL;
270 fp = setmntent(MOUNTED, "r");
273 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
277 while (feof(fp) == 0 && ferror(fp) ==0) {
278 if (llapi_is_lustre_mnttype(mnt->mnt_type)) {
279 rc = llapi_find(mnt->mnt_dir, obduuid, 0, 0, 0);
282 "error: lfs osts failed on %s\n",
293 static int lfs_check(int argc, char **argv)
297 struct mntent *mnt = NULL;
306 obd_types[0] = obd_type1;
307 obd_types[1] = obd_type2;
309 if (strcmp(argv[1], "osts") == 0) {
310 strcpy(obd_types[0], "osc");
311 } else if (strcmp(argv[1], "mds") == 0) {
312 strcpy(obd_types[0], "mdc");
313 } else if (strcmp(argv[1], "servers") == 0) {
315 strcpy(obd_types[0], "osc");
316 strcpy(obd_types[1], "mdc");
318 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
323 fp = setmntent(MOUNTED, "r");
325 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
329 while (feof(fp) == 0 && ferror(fp) ==0) {
330 if (llapi_is_lustre_mnttype(mnt->mnt_type))
337 rc = llapi_target_check(num_types, obd_types, mnt->mnt_dir);
340 fprintf(stderr, "error: %s: %s status failed\n",
347 static int lfs_catinfo(int argc, char **argv)
350 struct mntent *mnt = NULL;
353 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
356 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
359 fp = setmntent(MOUNTED, "r");
361 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
365 while (feof(fp) == 0 && ferror(fp) == 0) {
366 if (llapi_is_lustre_mnttype(mnt->mnt_type))
375 rc = llapi_catinfo(mnt->mnt_dir, argv[1], argv[2]);
377 rc = llapi_catinfo(mnt->mnt_dir, argv[1], NULL);
379 fprintf(stderr, "no lustre_lite mounted.\n");
386 int main(int argc, char **argv)
392 ptl_initialize(argc, argv);
393 if (obd_initialize(argc, argv) < 0)
395 if (dbg_initialize(argc, argv) < 0)
398 Parser_init("lfs > ", cmdlist);
401 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
403 rc = Parser_commands();
406 obd_finalize(argc, argv);