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>
44 static int lfs_setstripe(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, -1 all)"},
61 "To list the extended attributes for a given filename or files in a\n"
62 "directory or recursively for all files in a directory tree.\n"
63 "usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
64 {"getstripe", lfs_getstripe, 0,
65 "To list the striping pattern for given filename.\n"
66 "usage:getstripe <filename>"},
67 {"check", lfs_check, 0,
68 "Display the status of MDS or OSTs (as specified in the command)\n"
69 "or all the servers (MDS and OSTs).\n"
70 "usage: check <osts|mds|servers>"},
71 {"catinfo", lfs_catinfo, 0,
72 "Show information of specified type logs.\n"
73 "usage: catinfo {keyword} [node name]\n"
74 "\tkeywords are one of followings: config, deletions.\n"
75 "\tnode name must be provided when use keyword config."},
76 {"osts", lfs_osts, 0, "osts"},
77 {"help", Parser_help, 0, "help"},
78 {"exit", Parser_quit, 0, "quit"},
79 {"quit", Parser_quit, 0, "quit"},
84 static int lfs_setstripe(int argc, char **argv)
88 int st_offset, st_count;
95 // get the stripe size
96 st_size = strtoul(argv[2], &end, 0);
98 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
102 /* 64 KB is the largest common page size I'm aware of (on ia64), but
103 * check the local page size just in case. */
105 if (getpagesize() > page_size) {
106 fprintf(stderr, "WARNING: your page size (%d) is larger than "
107 "expected.\n", getpagesize());
108 page_size = getpagesize();
110 if (st_size % page_size) {
111 fprintf(stderr, "FATAL: stripe_size must be an even multiple "
112 "of %d bytes.\n", page_size);
116 // get the stripe offset
117 st_offset = strtoul(argv[3], &end, 0);
119 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
123 // get the stripe count
124 st_count = strtoul(argv[4], &end, 0);
126 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
131 result = llapi_file_create(argv[1], st_size, st_offset, st_count, 0);
133 fprintf(stderr, "error: %s: create stripe file failed\n",
139 static int lfs_find(int argc, char **argv)
141 struct option long_opts[] = {
143 {"quiet", 0, 0, 'q'},
144 {"recursive", 0, 0, 'r'},
145 {"verbose", 0, 0, 'v'},
148 char short_opts[] = "ho:qrv";
149 int quiet, verbose, recursive, c, rc;
150 struct obd_uuid *obduuid = NULL;
153 quiet = verbose = recursive = 0;
154 while ((c = getopt_long(argc, argv, short_opts,
155 long_opts, NULL)) != -1) {
160 "error: %s: only one obduuid allowed",
164 obduuid = (struct obd_uuid *)optarg;
181 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
182 argv[0], argv[optind - 1]);
192 rc = llapi_find(argv[optind], obduuid, recursive,verbose,quiet);
193 } while (++optind < argc && !rc);
196 fprintf(stderr, "error: %s: find failed\n", argv[0]);
200 static int lfs_getstripe(int argc, char **argv)
202 struct option long_opts[] = {
203 {"quiet", 0, 0, 'q'},
204 {"verbose", 0, 0, 'v'},
207 char short_opts[] = "qv";
208 int quiet, verbose, recursive, c, rc;
209 struct obd_uuid *obduuid = NULL;
212 quiet = verbose = recursive = 0;
213 while ((c = getopt_long(argc, argv, short_opts,
214 long_opts, NULL)) != -1) {
219 "error: %s: only one obduuid allowed",
223 obduuid = (struct obd_uuid *)optarg;
237 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
238 argv[0], argv[optind - 1]);
248 rc = llapi_find(argv[optind], obduuid, recursive,verbose,quiet);
249 } while (++optind < argc && !rc);
252 fprintf(stderr, "error: %s: getstripe failed for %s\n",
258 static int lfs_osts(int argc, char **argv)
261 struct mntent *mnt = NULL;
262 struct obd_uuid *obduuid = NULL;
268 fp = setmntent(MOUNTED, "r");
271 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
275 while (feof(fp) == 0 && ferror(fp) ==0) {
276 if (llapi_is_lustre_mnttype(mnt->mnt_type)) {
277 rc = llapi_find(mnt->mnt_dir, obduuid, 0, 0, 0);
280 "error: lfs osts failed on %s\n",
291 static int lfs_check(int argc, char **argv)
295 struct mntent *mnt = NULL;
304 obd_types[0] = obd_type1;
305 obd_types[1] = obd_type2;
307 if (strcmp(argv[1], "osts") == 0) {
308 strcpy(obd_types[0], "osc");
309 } else if (strcmp(argv[1], "mds") == 0) {
310 strcpy(obd_types[0], "mdc");
311 } else if (strcmp(argv[1], "servers") == 0) {
313 strcpy(obd_types[0], "osc");
314 strcpy(obd_types[1], "mdc");
316 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
321 fp = setmntent(MOUNTED, "r");
323 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
327 while (feof(fp) == 0 && ferror(fp) ==0) {
328 if (llapi_is_lustre_mnttype(mnt->mnt_type))
335 rc = llapi_target_check(num_types, obd_types, mnt->mnt_dir);
338 fprintf(stderr, "error: %s: %s status failed\n",
345 static int lfs_catinfo(int argc, char **argv)
348 struct mntent *mnt = NULL;
351 if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3))
354 if (strcmp(argv[1], "config") && strcmp(argv[1], "deletions"))
357 fp = setmntent(MOUNTED, "r");
359 fprintf(stderr, "setmntent(%s): %s:", MOUNTED,
363 while (feof(fp) == 0 && ferror(fp) == 0) {
364 if (llapi_is_lustre_mnttype(mnt->mnt_type))
373 rc = llapi_catinfo(mnt->mnt_dir, argv[1], argv[2]);
375 rc = llapi_catinfo(mnt->mnt_dir, argv[1], NULL);
377 fprintf(stderr, "no lustre_lite mounted.\n");
384 int main(int argc, char **argv)
390 ptl_initialize(argc, argv);
391 if (obd_initialize(argc, argv) < 0)
393 if (dbg_initialize(argc, argv) < 0)
396 Parser_init("lfs > ", cmdlist);
399 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
401 rc = Parser_commands();
404 obd_finalize(argc, argv);