4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
40 * Author: Robert Read <rread@clusterfs.com>
56 #include <sys/types.h>
62 #ifdef HAVE_SYS_QUOTA_H
63 # include <sys/quota.h>
69 #include <lnet/api-support.h>
70 #include <lnet/lnetctl.h>
72 #include <liblustre.h>
73 #include <lustre/lustre_idl.h>
74 #include <lustre/liblustreapi.h>
75 #include <lustre/lustre_user.h>
76 #include <lustre_quota.h>
78 #include <libcfs/libcfsutil.h>
82 static int lfs_setstripe(int argc, char **argv);
83 static int lfs_find(int argc, char **argv);
84 static int lfs_getstripe(int argc, char **argv);
85 static int lfs_osts(int argc, char **argv);
86 static int lfs_mdts(int argc, char **argv);
87 static int lfs_df(int argc, char **argv);
88 static int lfs_getname(int argc, char **argv);
89 static int lfs_check(int argc, char **argv);
90 #ifdef HAVE_SYS_QUOTA_H
91 static int lfs_quotacheck(int argc, char **argv);
92 static int lfs_quotaon(int argc, char **argv);
93 static int lfs_quotaoff(int argc, char **argv);
94 static int lfs_setquota(int argc, char **argv);
95 static int lfs_quota(int argc, char **argv);
97 static int lfs_flushctx(int argc, char **argv);
98 static int lfs_join(int argc, char **argv);
99 static int lfs_lsetfacl(int argc, char **argv);
100 static int lfs_lgetfacl(int argc, char **argv);
101 static int lfs_rsetfacl(int argc, char **argv);
102 static int lfs_rgetfacl(int argc, char **argv);
103 static int lfs_cp(int argc, char **argv);
104 static int lfs_ls(int argc, char **argv);
105 static int lfs_poollist(int argc, char **argv);
106 static int lfs_changelog(int argc, char **argv);
107 static int lfs_changelog_clear(int argc, char **argv);
108 static int lfs_fid2path(int argc, char **argv);
109 static int lfs_path2fid(int argc, char **argv);
110 static int lfs_data_version(int argc, char **argv);
112 /* all avaialable commands */
113 command_t cmdlist[] = {
114 {"setstripe", lfs_setstripe, 0,
115 "Create a new file with a specific striping pattern or\n"
116 "set the default striping pattern on an existing directory or\n"
117 "delete the default striping pattern from an existing directory\n"
118 "usage: setstripe [--stripe-count|-c <stripe_count>]\n"
119 " [--stripe-index|-i <start_ost_idx>]\n"
120 " [--stripe-size|-S <stripe_size>]\n"
121 " [--pool|-p <pool_name>] <directory|filename>\n"
123 " setstripe -d <directory> (to delete default striping)\n"
124 "\tstripe_size: Number of bytes on each OST (0 filesystem default)\n"
125 "\t Can be specified with k, m or g (in KB, MB and GB\n"
127 "\tstart_ost_idx: OST index of first stripe (-1 default)\n"
128 "\tstripe_count: Number of OSTs to stripe over (0 default, -1 all)\n"
129 "\tpool_name: Name of OST pool to use (default none)"},
130 {"getstripe", lfs_getstripe, 0,
131 "To list the striping info for a given file or files in a\n"
132 "directory or recursively for all files in a directory tree.\n"
133 "usage: getstripe [--ost|-O <uuid>] [--quiet | -q] [--verbose | -v]\n"
134 " [--stripe-count|-c] [--stripe-index|-i]\n"
135 " [--pool|-p] [--stripe-size|-S] [--directory|-d]\n"
136 " [--mdt-index|-M] [--recursive|-r] [--raw|-R]\n"
137 " <directory|filename> ..."},
138 {"pool_list", lfs_poollist, 0,
139 "List pools or pool OSTs\n"
140 "usage: pool_list <fsname>[.<pool>] | <pathname>\n"},
141 {"find", lfs_find, 0,
142 "find files matching given attributes recursively in directory tree.\n"
143 "usage: find <directory|filename> ...\n"
144 " [[!] --atime|-A [+-]N] [[!] --ctime|-C [+-]N]\n"
145 " [[!] --mtime|-M [+-]N] [[!] --mdt|-m <uuid|index,...>]\n"
146 " [--maxdepth|-D N] [[!] --name|-n <pattern>]\n"
147 " [[!] --ost|-O <uuid|index,...>] [--print|-p] [--print0|-P]\n"
148 " [[!] --size|-s [+-]N[bkMGTPE]]\n"
149 " [[!] --stripe-count|-c [+-]<stripes>]\n"
150 " [[!] --stripe-index|-i <index,...>]\n"
151 " [[!] --stripe-size|-S [+-]N[kMGT]] [[!] --type|-t <filetype>]\n"
152 " [[!] --gid|-g|--group|-G <gid>|<gname>]\n"
153 " [[!] --uid|-u|--user|-U <uid>|<uname>] [[!] --pool <pool>]\n"
154 "\t !: used before an option indicates 'NOT' requested attribute\n"
155 "\t -: used before a value indicates 'AT MOST' requested value\n"
156 "\t +: used before a value indicates 'AT LEAST' requested value\n"},
157 {"check", lfs_check, 0,
158 "Display the status of MDS or OSTs (as specified in the command)\n"
159 "or all the servers (MDS and OSTs).\n"
160 "usage: check <osts|mds|servers>"},
161 {"join", lfs_join, 0,
162 "join two lustre files into one.\n"
163 "obsolete, HEAD does not support it anymore.\n"},
164 {"osts", lfs_osts, 0, "list OSTs connected to client "
165 "[for specified path only]\n" "usage: osts [path]"},
166 {"mdts", lfs_mdts, 0, "list MDTs connected to client "
167 "[for specified path only]\n" "usage: mdts [path]"},
169 "report filesystem disk space usage or inodes usage"
170 "of each MDS and all OSDs or a batch belonging to a specific pool .\n"
171 "Usage: df [-i] [-h] [--pool|-p <fsname>[.<pool>] [path]"},
172 {"getname", lfs_getname, 0, "list instances and specified mount points "
173 "[for specified path only]\n"
174 "Usage: getname [-h]|[path ...] "},
175 #ifdef HAVE_SYS_QUOTA_H
176 {"quotacheck", lfs_quotacheck, 0,
177 "Scan the specified filesystem for disk usage, and create,\n"
178 "or update quota files. Deprecated as of 2.4.0.\n"
179 "usage: quotacheck [ -ug ] <filesystem>"},
180 {"quotaon", lfs_quotaon, 0, "Turn filesystem"
181 " quotas on. Deprecated as of 2.4.0.\n"
182 "usage: quotaon [ -ugf ] <filesystem>"},
183 {"quotaoff", lfs_quotaoff, 0, "Turn filesystem"
184 " quotas off. Deprecated as of 2.4.0.\n"
185 "usage: quotaoff [ -ug ] <filesystem>"},
186 {"setquota", lfs_setquota, 0, "Set filesystem quotas.\n"
187 "usage: setquota <-u|-g> <uname>|<uid>|<gname>|<gid>\n"
188 " -b <block-softlimit> -B <block-hardlimit>\n"
189 " -i <inode-softlimit> -I <inode-hardlimit> <filesystem>\n"
190 " setquota <-u|--user|-g|--group> <uname>|<uid>|<gname>|<gid>\n"
191 " [--block-softlimit <block-softlimit>]\n"
192 " [--block-hardlimit <block-hardlimit>]\n"
193 " [--inode-softlimit <inode-softlimit>]\n"
194 " [--inode-hardlimit <inode-hardlimit>] <filesystem>\n"
195 " setquota [-t] <-u|--user|-g|--group>\n"
196 " [--block-grace <block-grace>]\n"
197 " [--inode-grace <inode-grace>] <filesystem>\n"
198 " -b can be used instead of --block-softlimit/--block-grace\n"
199 " -B can be used instead of --block-hardlimit\n"
200 " -i can be used instead of --inode-softlimit/--inode-grace\n"
201 " -I can be used instead of --inode-hardlimit"},
202 {"quota", lfs_quota, 0, "Display disk usage and limits.\n"
203 "usage: quota [-q] [-v] [-o <obd_uuid>|-i <mdt_idx>|-I <ost_idx>]\n"
204 " [<-u|-g> <uname>|<uid>|<gname>|<gid>] <filesystem>\n"
205 " quota [-o <obd_uuid>|-i <mdt_idx>|-I <ost_idx>] -t <-u|-g> <filesystem>"},
207 {"flushctx", lfs_flushctx, 0, "Flush security context for current user.\n"
208 "usage: flushctx [-k] [mountpoint...]"},
209 {"lsetfacl", lfs_lsetfacl, 0,
210 "Remote user setfacl for user/group on the same remote client.\n"
211 "usage: lsetfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ..."},
212 {"lgetfacl", lfs_lgetfacl, 0,
213 "Remote user getfacl for user/group on the same remote client.\n"
214 "usage: lgetfacl [-dRLPvh] file ..."},
215 {"rsetfacl", lfs_rsetfacl, 0,
216 "Remote user setfacl for user/group on other clients.\n"
217 "usage: rsetfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ..."},
218 {"rgetfacl", lfs_rgetfacl, 0,
219 "Remote user getfacl for user/group on other clients.\n"
220 "usage: rgetfacl [-dRLPvh] file ..."},
222 "Remote user copy files and directories.\n"
223 "usage: cp [OPTION]... [-T] SOURCE DEST\n\tcp [OPTION]... SOURCE... DIRECTORY\n\tcp [OPTION]... -t DIRECTORY SOURCE..."},
225 "Remote user list directory contents.\n"
226 "usage: ls [OPTION]... [FILE]..."},
227 {"changelog", lfs_changelog, 0,
228 "Show the metadata changes on an MDT."
229 "\nusage: changelog <mdtname> [startrec [endrec]]"},
230 {"changelog_clear", lfs_changelog_clear, 0,
231 "Indicate that old changelog records up to <endrec> are no longer of "
232 "interest to consumer <id>, allowing the system to free up space.\n"
233 "An <endrec> of 0 means all records.\n"
234 "usage: changelog_clear <mdtname> <id> <endrec>"},
235 {"fid2path", lfs_fid2path, 0,
236 "Resolve the full path to a given FID. For a specific hardlink "
237 "specify link number <linkno>.\n"
238 /* "For a historical name, specify changelog record <recno>.\n" */
239 "usage: fid2path <fsname|rootpath> <fid> [--link <linkno>]"
240 /*[--rec <recno>]*/},
241 {"path2fid", lfs_path2fid, 0, "Display the fid for a given path.\n"
242 "usage: path2fid <path>"},
243 {"data_version", lfs_data_version, 0, "Display file data version for "
244 "a given path.\n" "usage: data_version [-n] <path>"},
245 {"help", Parser_help, 0, "help"},
246 {"exit", Parser_quit, 0, "quit"},
247 {"quit", Parser_quit, 0, "quit"},
251 static int isnumber(const char *str)
255 if (str[0] != '-' && !isdigit(str[0]))
258 for (ptr = str + 1; *ptr != '\0'; ptr++) {
267 static int lfs_setstripe(int argc, char **argv)
271 unsigned long long st_size;
272 int st_offset, st_count;
276 char *stripe_size_arg = NULL;
277 char *stripe_off_arg = NULL;
278 char *stripe_count_arg = NULL;
279 char *pool_name_arg = NULL;
280 unsigned long long size_units = 1;
282 struct option long_opts[] = {
283 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
284 #warning "remove deprecated --count option"
286 /* This formerly implied "stripe-count", but was explicitly
287 * made "stripe-count" for consistency with other options,
288 * and to separate it from "mdt-count" when DNE arrives. */
289 {"count", required_argument, 0, 'c'},
291 {"stripe-count", required_argument, 0, 'c'},
292 {"stripe_count", required_argument, 0, 'c'},
293 {"delete", no_argument, 0, 'd'},
294 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
295 #warning "remove deprecated --index option"
297 /* This formerly implied "stripe-index", but was explicitly
298 * made "stripe-index" for consistency with other options,
299 * and to separate it from "mdt-index" when DNE arrives. */
300 {"index", required_argument, 0, 'i'},
302 {"stripe-index", required_argument, 0, 'i'},
303 {"stripe_index", required_argument, 0, 'i'},
304 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
305 #warning "remove deprecated --offset option"
307 /* This formerly implied "stripe-index", but was confusing
308 * with "file offset" (which will eventually be needed for
309 * with different layouts by offset), so deprecate it. */
310 {"offset", required_argument, 0, 'o'},
312 {"pool", required_argument, 0, 'p'},
313 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
314 #warning "remove deprecated --size option"
316 /* This formerly implied "--stripe-size", but was confusing
317 * with "lfs find --size|-s", which means "file size", so use
318 * the consistent "--stripe-size|-S" for all commands. */
319 {"size", required_argument, 0, 's'},
321 {"stripe-size", required_argument, 0, 'S'},
322 {"stripe_size", required_argument, 0, 'S'},
330 #if LUSTRE_VERSION < OBD_OCD_VERSION(2,4,50,0)
331 if (argc == 5 && argv[1][0] != '-' &&
332 isnumber(argv[2]) && isnumber(argv[3]) && isnumber(argv[4])) {
333 fprintf(stderr, "error: obsolete usage of setstripe "
334 "positional parameters. Use -c, -i, -S instead.\n");
338 #warning "remove obsolete positional parameter error"
342 while ((c = getopt_long(argc, argv, "c:di:o:p:s:S:",
343 long_opts, NULL)) >= 0) {
349 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
350 #warning "remove deprecated --count option"
351 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
352 if (strcmp(argv[optind - 1], "--count") == 0)
353 fprintf(stderr, "warning: '--count' deprecated"
354 ", use '--stripe-count' instead\n");
356 stripe_count_arg = optarg;
359 /* delete the default striping pattern */
363 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,4,50,0)
364 fprintf(stderr, "warning: '--offset|-o' deprecated, "
365 "use '--stripe-index|-i' instead\n");
367 if (strcmp(argv[optind - 1], "--offset") == 0)
368 /* need --stripe-index established first */
369 fprintf(stderr, "warning: '--offset' deprecated"
370 ", use '--index' instead\n");
373 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
374 #warning "remove deprecated --offset and --index options"
375 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
376 if (strcmp(argv[optind - 1], "--index") == 0)
377 fprintf(stderr, "warning: '--index' deprecated"
378 ", use '--stripe-index' instead\n");
380 stripe_off_arg = optarg;
383 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
384 #warning "remove deprecated --size option"
385 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
386 fprintf(stderr, "warning: '--size|-s' deprecated, "
387 "use '--stripe-size|-S' instead\n");
390 stripe_size_arg = optarg;
393 pool_name_arg = optarg;
400 fname = argv[optind];
403 (stripe_size_arg != NULL || stripe_off_arg != NULL ||
404 stripe_count_arg != NULL || pool_name_arg != NULL)) {
405 fprintf(stderr, "error: %s: cannot specify -d with "
406 "-s, -c, -o, or -p options\n",
412 if (optind == argc) {
413 fprintf(stderr, "error: %s: missing filename|dirname\n",
418 /* get the stripe size */
419 if (stripe_size_arg != NULL) {
420 result = parse_size(stripe_size_arg, &st_size, &size_units, 0);
422 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
423 argv[0], stripe_size_arg);
427 /* get the stripe offset */
428 if (stripe_off_arg != NULL) {
429 st_offset = strtol(stripe_off_arg, &end, 0);
431 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
432 argv[0], stripe_off_arg);
436 /* get the stripe count */
437 if (stripe_count_arg != NULL) {
438 st_count = strtoul(stripe_count_arg, &end, 0);
440 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
441 argv[0], stripe_count_arg);
447 result = llapi_file_create_pool(fname, st_size, st_offset,
448 st_count, 0, pool_name_arg);
450 fprintf(stderr,"error: %s: create stripe file '%s' "
451 "failed\n", argv[0], fname);
454 fname = argv[++optind];
455 } while (fname != NULL);
460 static int lfs_poollist(int argc, char **argv)
465 return llapi_poollist(argv[1]);
468 static int set_time(time_t *time, time_t *set, char *str)
475 else if (str[0] == '-')
481 t = strtol(str, NULL, 0);
482 if (*time < t * 24 * 60 * 60) {
485 fprintf(stderr, "Wrong time '%s' is specified.\n", str);
489 *set = *time - t * 24 * 60 * 60;
496 static int name2id(unsigned int *id, char *name, int type)
499 struct passwd *entry;
501 if (!(entry = getpwnam(name))) {
511 if (!(entry = getgrnam(name))) {
523 static int id2name(char **name, unsigned int id, int type)
526 struct passwd *entry;
528 if (!(entry = getpwuid(id))) {
534 *name = entry->pw_name;
538 if (!(entry = getgrgid(id))) {
544 *name = entry->gr_name;
550 #define FIND_POOL_OPT 3
551 static int lfs_find(int argc, char **argv)
555 struct find_param param = { .maxdepth = -1, .quiet = 1 };
556 struct option long_opts[] = {
557 {"atime", required_argument, 0, 'A'},
558 {"stripe-count", required_argument, 0, 'c'},
559 {"stripe_count", required_argument, 0, 'c'},
560 {"ctime", required_argument, 0, 'C'},
561 {"maxdepth", required_argument, 0, 'D'},
562 {"gid", required_argument, 0, 'g'},
563 {"group", required_argument, 0, 'G'},
564 {"stripe-index", required_argument, 0, 'i'},
565 {"stripe_index", required_argument, 0, 'i'},
566 {"mdt", required_argument, 0, 'm'},
567 {"mtime", required_argument, 0, 'M'},
568 {"name", required_argument, 0, 'n'},
569 /* reserve {"or", no_argument, , 0, 'o'}, to match find(1) */
570 {"obd", required_argument, 0, 'O'},
571 {"ost", required_argument, 0, 'O'},
572 /* no short option for pool, p/P already used */
573 {"pool", required_argument, 0, FIND_POOL_OPT},
574 {"print0", no_argument, 0, 'p'},
575 {"print", no_argument, 0, 'P'},
576 {"size", required_argument, 0, 's'},
577 {"stripe-size", required_argument, 0, 'S'},
578 {"stripe_size", required_argument, 0, 'S'},
579 {"type", required_argument, 0, 't'},
580 {"uid", required_argument, 0, 'u'},
581 {"user", required_argument, 0, 'U'},
595 /* when getopt_long_only() hits '!' it returns 1, puts "!" in optarg */
596 while ((c = getopt_long_only(argc, argv,
597 "-A:c:C:D:g:G:i:m:M:n:O:Ppqrs:S:t:u:U:v",
598 long_opts, NULL)) >= 0) {
603 /* '!' is part of option */
604 /* when getopt_long_only() finds a string which is not
605 * an option nor a known option argument it returns 1
606 * in that case if we already have found pathstart and pathend
607 * (i.e. we have the list of pathnames),
608 * the only supported value is "!"
610 isoption = (c != 1) || (strcmp(optarg, "!") == 0);
611 if (!isoption && pathend != -1) {
612 fprintf(stderr, "err: %s: filename|dirname must either "
613 "precede options or follow options\n",
618 if (!isoption && pathstart == -1)
619 pathstart = optind - 1;
620 if (isoption && pathstart != -1 && pathend == -1)
621 pathend = optind - 2;
627 /* unknown; opt is "!" or path component,
628 * checking done above.
630 if (strcmp(optarg, "!") == 0)
634 xtime = ¶m.atime;
635 xsign = ¶m.asign;
636 param.exclude_atime = !!neg_opt;
637 /* no break, this falls through to 'C' for ctime */
640 xtime = ¶m.ctime;
641 xsign = ¶m.csign;
642 param.exclude_ctime = !!neg_opt;
644 /* no break, this falls through to 'M' for mtime */
647 xtime = ¶m.mtime;
648 xsign = ¶m.msign;
649 param.exclude_mtime = !!neg_opt;
651 ret = set_time(&t, xtime, optarg);
652 if (ret == INT_MAX) {
660 if (optarg[0] == '+') {
661 param.stripecount_sign = -1;
663 } else if (optarg[0] == '-') {
664 param.stripecount_sign = 1;
668 param.stripecount = strtoul(optarg, &endptr, 0);
669 if (*endptr != '\0') {
670 fprintf(stderr,"error: bad stripe_count '%s'\n",
675 param.check_stripecount = 1;
676 param.exclude_stripecount = !!neg_opt;
679 param.maxdepth = strtol(optarg, 0, 0);
683 ret = name2id(¶m.gid, optarg, GROUP);
685 param.gid = strtoul(optarg, &endptr, 10);
686 if (*endptr != '\0') {
687 fprintf(stderr, "Group/GID: %s cannot "
688 "be found.\n", optarg);
693 param.exclude_gid = !!neg_opt;
698 ret = name2id(¶m.uid, optarg, USER);
700 param.uid = strtoul(optarg, &endptr, 10);
701 if (*endptr != '\0') {
702 fprintf(stderr, "User/UID: %s cannot "
703 "be found.\n", optarg);
708 param.exclude_uid = !!neg_opt;
712 if (strlen(optarg) > LOV_MAXPOOLNAME) {
714 "Pool name %s is too long"
715 " (max is %d)\n", optarg,
720 /* we do check for empty pool because empty pool
721 * is used to find V1 lov attributes */
722 strncpy(param.poolname, optarg, LOV_MAXPOOLNAME);
723 param.poolname[LOV_MAXPOOLNAME] = '\0';
724 param.exclude_pool = !!neg_opt;
725 param.check_pool = 1;
728 param.pattern = (char *)optarg;
729 param.exclude_pattern = !!neg_opt;
734 char *buf, *token, *next, *p;
738 buf = strdup(optarg);
744 param.exclude_obd = !!neg_opt;
747 while (token && *token) {
748 token = strchr(token, ',');
755 param.exclude_mdt = !!neg_opt;
756 param.num_alloc_mdts += len;
757 tmp = realloc(param.mdtuuid,
758 param.num_alloc_mdts *
759 sizeof(*param.mdtuuid));
761 GOTO(err_free, ret = -ENOMEM);
764 param.exclude_obd = !!neg_opt;
765 param.num_alloc_obds += len;
766 tmp = realloc(param.obduuid,
767 param.num_alloc_obds *
768 sizeof(*param.obduuid));
770 GOTO(err_free, ret = -ENOMEM);
773 for (token = buf; token && *token; token = next) {
777 param.mdtuuid[param.num_mdts++].uuid;
780 param.obduuid[param.num_obds++].uuid;
781 p = strchr(token, ',');
787 strcpy((char *)uuid, token);
800 if (optarg[0] == '+') {
801 param.size_sign = -1;
803 } else if (optarg[0] == '-') {
808 ret = parse_size(optarg, ¶m.size,
809 ¶m.size_units, 0);
811 fprintf(stderr, "error: bad file size '%s'\n",
815 param.check_size = 1;
816 param.exclude_size = !!neg_opt;
819 if (optarg[0] == '+') {
820 param.stripesize_sign = -1;
822 } else if (optarg[0] == '-') {
823 param.stripesize_sign = 1;
827 ret = parse_size(optarg, ¶m.stripesize,
828 ¶m.stripesize_units, 0);
830 fprintf(stderr, "error: bad stripe_size '%s'\n",
834 param.check_stripesize = 1;
835 param.exclude_stripesize = !!neg_opt;
838 param.exclude_type = !!neg_opt;
840 case 'b': param.type = S_IFBLK; break;
841 case 'c': param.type = S_IFCHR; break;
842 case 'd': param.type = S_IFDIR; break;
843 case 'f': param.type = S_IFREG; break;
844 case 'l': param.type = S_IFLNK; break;
845 case 'p': param.type = S_IFIFO; break;
846 case 's': param.type = S_IFSOCK; break;
847 #ifdef S_IFDOOR /* Solaris only */
848 case 'D': param.type = S_IFDOOR; break;
850 default: fprintf(stderr, "error: %s: bad type '%s'\n",
862 if (pathstart == -1) {
863 fprintf(stderr, "error: %s: no filename|pathname\n",
867 } else if (pathend == -1) {
873 ret = llapi_find(argv[pathstart], ¶m);
874 } while (++pathstart < pathend && !ret);
877 fprintf(stderr, "error: %s failed for %s.\n",
878 argv[0], argv[optind - 1]);
880 if (param.obduuid && param.num_alloc_obds)
883 if (param.mdtuuid && param.num_alloc_mdts)
889 static int lfs_getstripe(int argc, char **argv)
891 struct option long_opts[] = {
892 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
893 #warning "remove deprecated --count option"
895 /* This formerly implied "stripe-count", but was explicitly
896 * made "stripe-count" for consistency with other options,
897 * and to separate it from "mdt-count" when DNE arrives. */
898 {"count", no_argument, 0, 'c'},
900 {"stripe-count", no_argument, 0, 'c'},
901 {"stripe_count", no_argument, 0, 'c'},
902 {"directory", no_argument, 0, 'd'},
903 {"generation", no_argument, 0, 'g'},
904 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
905 #warning "remove deprecated --index option"
907 /* This formerly implied "stripe-index", but was explicitly
908 * made "stripe-index" for consistency with other options,
909 * and to separate it from "mdt-index" when DNE arrives. */
910 {"index", no_argument, 0, 'i'},
912 {"stripe-index", no_argument, 0, 'i'},
913 {"stripe_index", no_argument, 0, 'i'},
914 {"mdt-index", no_argument, 0, 'M'},
915 {"mdt_index", no_argument, 0, 'M'},
916 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
917 #warning "remove deprecated --offset option"
919 /* This formerly implied "stripe-index", but was confusing
920 * with "file offset" (which will eventually be needed for
921 * with different layouts by offset), so deprecate it. */
922 {"offset", no_argument, 0, 'o'},
924 {"obd", required_argument, 0, 'O'},
925 {"ost", required_argument, 0, 'O'},
926 {"pool", no_argument, 0, 'p'},
927 {"quiet", no_argument, 0, 'q'},
928 {"recursive", no_argument, 0, 'r'},
929 {"raw", no_argument, 0, 'R'},
930 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
931 #warning "remove deprecated --size option"
933 /* This formerly implied "--stripe-size", but was confusing
934 * with "lfs find --size|-s", which means "file size", so use
935 * the consistent "--stripe-size|-S" for all commands. */
936 {"size", no_argument, 0, 's'},
938 {"stripe-size", no_argument, 0, 'S'},
939 {"stripe_size", no_argument, 0, 'S'},
940 {"verbose", no_argument, 0, 'v'},
944 struct find_param param = { 0 };
948 while ((c = getopt_long(argc, argv, "cdghiMoO:pqrRsSv",
949 long_opts, NULL)) != -1) {
954 "error: %s: only one obduuid allowed",
958 param.obduuid = (struct obd_uuid *)optarg;
970 param.verbose = VERBOSE_ALL | VERBOSE_DETAIL;
973 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
974 #warning "remove deprecated --count option"
975 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
976 if (strcmp(argv[optind - 1], "--count") == 0)
977 fprintf(stderr, "warning: '--count' deprecated,"
978 " use '--stripe-count' instead\n");
980 if (!(param.verbose & VERBOSE_DETAIL)) {
981 param.verbose |= VERBOSE_COUNT;
986 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
987 #warning "remove deprecated --size option"
988 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
989 fprintf(stderr, "warning: '--size|-s' deprecated, "
990 "use '--stripe-size|-S' instead\n");
993 if (!(param.verbose & VERBOSE_DETAIL)) {
994 param.verbose |= VERBOSE_SIZE;
999 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,4,50,0)
1000 fprintf(stderr, "warning: '--offset|-o' deprecated, "
1001 "use '--stripe-index|-i' instead\n");
1003 if (strcmp(argv[optind - 1], "--offset") == 0)
1004 /* need --stripe-index established first */
1005 fprintf(stderr, "warning: '--offset' deprecated"
1006 ", use '--index' instead\n");
1009 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
1010 #warning "remove deprecated --offset and --index options"
1011 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
1012 if (strcmp(argv[optind - 1], "--index") == 0)
1013 fprintf(stderr, "warning: '--index' deprecated"
1014 ", use '--stripe-index' instead\n");
1016 if (!(param.verbose & VERBOSE_DETAIL)) {
1017 param.verbose |= VERBOSE_OFFSET;
1022 if (!(param.verbose & VERBOSE_DETAIL)) {
1023 param.verbose |= VERBOSE_POOL;
1028 if (!(param.verbose & VERBOSE_DETAIL)) {
1029 param.verbose |= VERBOSE_GENERATION;
1034 if (!(param.verbose & VERBOSE_DETAIL))
1036 param.verbose |= VERBOSE_MDTINDEX;
1049 if (param.recursive)
1050 param.maxdepth = -1;
1053 param.verbose = VERBOSE_ALL;
1055 param.verbose = VERBOSE_OBJID;
1058 rc = llapi_getstripe(argv[optind], ¶m);
1059 } while (++optind < argc && !rc);
1062 fprintf(stderr, "error: %s failed for %s.\n",
1063 argv[0], argv[optind - 1]);
1067 static int lfs_tgts(int argc, char **argv)
1069 char mntdir[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'};
1070 struct find_param param;
1071 int index = 0, rc=0;
1076 if (argc == 2 && !realpath(argv[1], path)) {
1078 fprintf(stderr, "error: invalid path '%s': %s\n",
1079 argv[1], strerror(-rc));
1083 while (!llapi_search_mounts(path, index++, mntdir, NULL)) {
1084 /* Check if we have a mount point */
1085 if (mntdir[0] == '\0')
1088 memset(¶m, 0, sizeof(param));
1089 if (!strcmp(argv[0], "mdts"))
1092 rc = llapi_ostlist(mntdir, ¶m);
1094 fprintf(stderr, "error: %s: failed on %s\n",
1097 if (path[0] != '\0')
1099 memset(mntdir, 0, PATH_MAX);
1105 static int lfs_osts(int argc, char **argv)
1107 return lfs_tgts(argc, argv);
1110 static int lfs_mdts(int argc, char **argv)
1112 return lfs_tgts(argc, argv);
1115 #define COOK(value) \
1118 while (value > 1024) { \
1126 #define CDF "%11llu"
1127 #define HDF "%8.1f%c"
1131 static int showdf(char *mntdir, struct obd_statfs *stat,
1132 char *uuid, int ishow, int cooked,
1133 char *type, int index, int rc)
1135 long long avail, used, total;
1137 char *suffix = "KMGTPEZY";
1138 /* Note if we have >2^64 bytes/fs these buffers will need to be grown */
1139 char tbuf[20], ubuf[20], abuf[20], rbuf[20];
1147 avail = stat->os_ffree;
1148 used = stat->os_files - stat->os_ffree;
1149 total = stat->os_files;
1151 int shift = cooked ? 0 : 10;
1153 avail = (stat->os_bavail * stat->os_bsize) >> shift;
1154 used = ((stat->os_blocks - stat->os_bfree) *
1155 stat->os_bsize) >> shift;
1156 total = (stat->os_blocks * stat->os_bsize) >> shift;
1159 if ((used + avail) > 0)
1160 ratio = (double)used / (double)(used + avail);
1166 cook_val = (double)total;
1169 sprintf(tbuf, HDF, cook_val, suffix[i - 1]);
1171 sprintf(tbuf, CDF, total);
1173 cook_val = (double)used;
1176 sprintf(ubuf, HDF, cook_val, suffix[i - 1]);
1178 sprintf(ubuf, CDF, used);
1180 cook_val = (double)avail;
1183 sprintf(abuf, HDF, cook_val, suffix[i - 1]);
1185 sprintf(abuf, CDF, avail);
1187 sprintf(tbuf, CDF, total);
1188 sprintf(ubuf, CDF, used);
1189 sprintf(abuf, CDF, avail);
1192 sprintf(rbuf, RDF, (int)(ratio * 100 + 0.5));
1193 printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s",
1194 uuid, tbuf, ubuf, abuf, rbuf, mntdir);
1196 printf("[%s:%d]\n", type, index);
1202 printf(UUF": inactive device\n", uuid);
1205 printf(UUF": %s\n", uuid, strerror(-rc));
1212 struct ll_stat_type {
1217 static int mntdf(char *mntdir, char *fsname, char *pool, int ishow, int cooked)
1219 struct obd_statfs stat_buf, sum = { .os_bsize = 1 };
1220 struct obd_uuid uuid_buf;
1221 char *poolname = NULL;
1222 struct ll_stat_type types[] = { { LL_STATFS_LMV, "MDT" },
1223 { LL_STATFS_LOV, "OST" },
1225 struct ll_stat_type *tp;
1230 poolname = strchr(pool, '.');
1231 if (poolname != NULL) {
1232 if (strncmp(fsname, pool, strlen(fsname))) {
1233 fprintf(stderr, "filesystem name incorrect\n");
1242 printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s\n",
1243 "UUID", "Inodes", "IUsed", "IFree",
1244 "IUse%", "Mounted on");
1246 printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s\n",
1247 "UUID", cooked ? "bytes" : "1K-blocks",
1248 "Used", "Available", "Use%", "Mounted on");
1250 for (tp = types; tp->st_name != NULL; tp++) {
1251 for (index = 0; ; index++) {
1252 memset(&stat_buf, 0, sizeof(struct obd_statfs));
1253 memset(&uuid_buf, 0, sizeof(struct obd_uuid));
1254 rc = llapi_obd_statfs(mntdir, tp->st_op, index,
1255 &stat_buf, &uuid_buf);
1259 if (poolname && tp->st_op == LL_STATFS_LOV &&
1260 llapi_search_ost(fsname, poolname,
1261 obd_uuid2str(&uuid_buf)) != 1)
1264 /* the llapi_obd_statfs() call may have returned with
1265 * an error, but if it filled in uuid_buf we will at
1266 * lease use that to print out a message for that OBD.
1267 * If we didn't get anything in the uuid_buf, then fill
1268 * it in so that we can print an error message. */
1269 if (uuid_buf.uuid[0] == '\0')
1270 sprintf(uuid_buf.uuid, "%s%04x",
1271 tp->st_name, index);
1272 showdf(mntdir, &stat_buf, obd_uuid2str(&uuid_buf),
1273 ishow, cooked, tp->st_name, index, rc);
1276 if (tp->st_op == LL_STATFS_LMV) {
1277 sum.os_ffree += stat_buf.os_ffree;
1278 sum.os_files += stat_buf.os_files;
1279 } else /* if (tp->st_op == LL_STATFS_LOV) */ {
1280 sum.os_blocks += stat_buf.os_blocks *
1282 sum.os_bfree += stat_buf.os_bfree *
1284 sum.os_bavail += stat_buf.os_bavail *
1287 } else if (rc == -EINVAL || rc == -EFAULT) {
1294 showdf(mntdir, &sum, "filesystem summary:", ishow, cooked, NULL, 0,0);
1299 static int lfs_df(int argc, char **argv)
1301 char mntdir[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'};
1302 int ishow = 0, cooked = 0;
1303 int c, rc = 0, index = 0;
1304 char fsname[PATH_MAX] = "", *pool_name = NULL;
1305 struct option long_opts[] = {
1306 {"pool", required_argument, 0, 'p'},
1311 while ((c = getopt_long(argc, argv, "hip:", long_opts, NULL)) != -1) {
1326 if (optind < argc && !realpath(argv[optind], path)) {
1328 fprintf(stderr, "error: invalid path '%s': %s\n",
1329 argv[optind], strerror(-rc));
1333 while (!llapi_search_mounts(path, index++, mntdir, fsname)) {
1334 /* Check if we have a mount point */
1335 if (mntdir[0] == '\0')
1338 rc = mntdf(mntdir, fsname, pool_name, ishow, cooked);
1339 if (rc || path[0] != '\0')
1341 fsname[0] = '\0'; /* avoid matching in next loop */
1342 mntdir[0] = '\0'; /* avoid matching in next loop */
1348 static int lfs_getname(int argc, char **argv)
1350 char mntdir[PATH_MAX] = "", path[PATH_MAX] = "", fsname[PATH_MAX] = "";
1351 int rc = 0, index = 0, c;
1352 char buf[sizeof(struct obd_uuid)];
1355 while ((c = getopt(argc, argv, "h")) != -1)
1358 if (optind == argc) { /* no paths specified, get all paths. */
1359 while (!llapi_search_mounts(path, index++, mntdir, fsname)) {
1360 rc = llapi_getname(mntdir, buf, sizeof(buf));
1363 "cannot get name for `%s': %s\n",
1364 mntdir, strerror(-rc));
1368 printf("%s %s\n", buf, mntdir);
1370 path[0] = fsname[0] = mntdir[0] = 0;
1372 } else { /* paths specified, only attempt to search these. */
1373 for (; optind < argc; optind++) {
1374 rc = llapi_getname(argv[optind], buf, sizeof(buf));
1377 "cannot get name for `%s': %s\n",
1378 argv[optind], strerror(-rc));
1382 printf("%s %s\n", buf, argv[optind]);
1388 static int lfs_check(int argc, char **argv)
1391 char mntdir[PATH_MAX] = {'\0'};
1400 obd_types[0] = obd_type1;
1401 obd_types[1] = obd_type2;
1403 if (strcmp(argv[1], "osts") == 0) {
1404 strcpy(obd_types[0], "osc");
1405 } else if (strcmp(argv[1], "mds") == 0) {
1406 strcpy(obd_types[0], "mdc");
1407 } else if (strcmp(argv[1], "servers") == 0) {
1409 strcpy(obd_types[0], "osc");
1410 strcpy(obd_types[1], "mdc");
1412 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
1417 rc = llapi_search_mounts(NULL, 0, mntdir, NULL);
1418 if (rc < 0 || mntdir[0] == '\0') {
1419 fprintf(stderr, "No suitable Lustre mount found\n");
1423 rc = llapi_target_iterate(num_types, obd_types,
1424 mntdir, llapi_ping_target);
1427 fprintf(stderr, "error: %s: %s status failed\n",
1434 static int lfs_join(int argc, char **argv)
1436 fprintf(stderr, "join two lustre files into one.\n"
1437 "obsolete, HEAD does not support it anymore.\n");
1441 #ifdef HAVE_SYS_QUOTA_H
1442 static int lfs_quotacheck(int argc, char **argv)
1444 int c, check_type = 0;
1446 struct if_quotacheck qchk;
1447 struct if_quotactl qctl;
1448 char *obd_type = (char *)qchk.obd_type;
1451 memset(&qchk, 0, sizeof(qchk));
1454 while ((c = getopt(argc, argv, "gu")) != -1) {
1463 fprintf(stderr, "error: %s: option '-%c' "
1464 "unrecognized\n", argv[0], c);
1471 else /* do quotacheck for both user & group quota by default */
1479 rc = llapi_quotacheck(mnt, check_type);
1480 if (rc == -EOPNOTSUPP) {
1481 fprintf(stderr, "error: quotacheck not supported by the quota "
1482 "master.\nPlease note that quotacheck is deprecated as "
1483 "of lustre 2.4.0 since space accounting is always "
1484 "enabled.\nFilesystems not formatted with 2.4 utils or "
1485 "beyond can be upgraded with tunefs.lustre --quota.\n");
1488 fprintf(stderr, "quotacheck failed: %s\n", strerror(-rc));
1492 rc = llapi_poll_quotacheck(mnt, &qchk);
1495 fprintf(stderr, "%s %s ", obd_type,
1496 obd_uuid2str(&qchk.obd_uuid));
1497 fprintf(stderr, "quota check failed: %s\n", strerror(-rc));
1501 memset(&qctl, 0, sizeof(qctl));
1502 qctl.qc_cmd = LUSTRE_Q_QUOTAON;
1503 qctl.qc_type = check_type;
1504 rc = llapi_quotactl(mnt, &qctl);
1505 if (rc && rc != -EALREADY) {
1507 fprintf(stderr, "%s %s ", (char *)qctl.obd_type,
1508 obd_uuid2str(&qctl.obd_uuid));
1509 fprintf(stderr, "%s turn on quota failed: %s\n",
1510 argv[0], strerror(-rc));
1517 static int lfs_quotaon(int argc, char **argv)
1521 struct if_quotactl qctl;
1522 char *obd_type = (char *)qctl.obd_type;
1525 memset(&qctl, 0, sizeof(qctl));
1526 qctl.qc_cmd = LUSTRE_Q_QUOTAON;
1529 while ((c = getopt(argc, argv, "fgu")) != -1) {
1532 qctl.qc_type |= 0x01;
1535 qctl.qc_type |= 0x02;
1538 qctl.qc_cmd = LUSTRE_Q_QUOTAOFF;
1541 fprintf(stderr, "error: %s: option '-%c' "
1542 "unrecognized\n", argv[0], c);
1549 else /* by default, enable quota for both user & group */
1550 qctl.qc_type = 0x02;
1557 rc = llapi_quotactl(mnt, &qctl);
1559 if (rc == -EOPNOTSUPP) {
1560 fprintf(stderr, "error: quotaon not supported by the "
1561 "quota master.\nPlease note that quotaon/off is"
1562 " deprecated as of lustre 2.4.0.\nQuota "
1563 "enforcement should now be enabled on the MGS "
1564 "via:\nmgs# lctl conf_param ${FSNAME}.quota."
1565 "<ost|mdt>=<u|g|ug>\n(ost for block quota, mdt "
1566 "for inode quota, u for user and g for group"
1568 } else if (rc == -EALREADY) {
1570 } else if (rc == -ENOENT) {
1571 fprintf(stderr, "error: cannot find quota database, "
1572 "make sure you have run quotacheck\n");
1575 fprintf(stderr, "%s %s ", obd_type,
1576 obd_uuid2str(&qctl.obd_uuid));
1577 fprintf(stderr, "%s failed: %s\n", argv[0],
1585 static int lfs_quotaoff(int argc, char **argv)
1589 struct if_quotactl qctl;
1590 char *obd_type = (char *)qctl.obd_type;
1593 memset(&qctl, 0, sizeof(qctl));
1594 qctl.qc_cmd = LUSTRE_Q_QUOTAOFF;
1597 while ((c = getopt(argc, argv, "gu")) != -1) {
1600 qctl.qc_type |= 0x01;
1603 qctl.qc_type |= 0x02;
1606 fprintf(stderr, "error: %s: option '-%c' "
1607 "unrecognized\n", argv[0], c);
1614 else /* by default, disable quota for both user & group */
1615 qctl.qc_type = 0x02;
1622 rc = llapi_quotactl(mnt, &qctl);
1624 if (rc == -EOPNOTSUPP) {
1625 fprintf(stderr, "error: quotaoff not supported by the "
1626 "quota master.\nPlease note that quotaon/off is"
1627 " deprecated as of lustre 2.4.0.\nQuota "
1628 "enforcement can be disabled on the MGS via:\n"
1629 "mgs# lctl conf_param ${FSNAME}.quota.<ost|mdt>"
1631 } else if (rc == -EALREADY) {
1635 fprintf(stderr, "%s %s ", obd_type,
1636 obd_uuid2str(&qctl.obd_uuid));
1637 fprintf(stderr, "quotaoff failed: %s\n",
1645 #define ARG2INT(nr, str, msg) \
1648 nr = strtol(str, &endp, 0); \
1650 fprintf(stderr, "error: bad %s: %s\n", msg, str); \
1655 #define ADD_OVERFLOW(a,b) ((a + b) < a) ? (a = ULONG_MAX) : (a = a + b)
1657 /* Convert format time string "XXwXXdXXhXXmXXs" into seconds value
1658 * returns the value or ULONG_MAX on integer overflow or incorrect format
1660 * 1. the order of specifiers is arbitrary (may be: 5w3s or 3s5w)
1661 * 2. specifiers may be encountered multiple times (2s3s is 5 seconds)
1662 * 3. empty integer value is interpreted as 0
1664 static unsigned long str2sec(const char* timestr)
1666 const char spec[] = "smhdw";
1667 const unsigned long mult[] = {1, 60, 60*60, 24*60*60, 7*24*60*60};
1668 unsigned long val = 0;
1671 if (strpbrk(timestr, spec) == NULL) {
1672 /* no specifiers inside the time string,
1673 should treat it as an integer value */
1674 val = strtoul(timestr, &tail, 10);
1675 return *tail ? ULONG_MAX : val;
1678 /* format string is XXwXXdXXhXXmXXs */
1684 v = strtoul(timestr, &tail, 10);
1685 if (v == ULONG_MAX || *tail == '\0')
1686 /* value too large (ULONG_MAX or more)
1687 or missing specifier */
1690 ptr = strchr(spec, *tail);
1692 /* unknown specifier */
1697 /* check if product will overflow the type */
1698 if (!(v < ULONG_MAX / mult[ind]))
1701 ADD_OVERFLOW(val, mult[ind] * v);
1702 if (val == ULONG_MAX)
1714 #define ARG2ULL(nr, str, def_units) \
1716 unsigned long long limit, units = def_units; \
1719 rc = parse_size(str, &limit, &units, 1); \
1721 fprintf(stderr, "error: bad limit value %s\n", str); \
1727 static inline int has_times_option(int argc, char **argv)
1731 for (i = 1; i < argc; i++)
1732 if (!strcmp(argv[i], "-t"))
1738 int lfs_setquota_times(int argc, char **argv)
1741 struct if_quotactl qctl;
1742 char *mnt, *obd_type = (char *)qctl.obd_type;
1743 struct obd_dqblk *dqb = &qctl.qc_dqblk;
1744 struct obd_dqinfo *dqi = &qctl.qc_dqinfo;
1745 struct option long_opts[] = {
1746 {"block-grace", required_argument, 0, 'b'},
1747 {"group", no_argument, 0, 'g'},
1748 {"inode-grace", required_argument, 0, 'i'},
1749 {"times", no_argument, 0, 't'},
1750 {"user", no_argument, 0, 'u'},
1754 memset(&qctl, 0, sizeof(qctl));
1755 qctl.qc_cmd = LUSTRE_Q_SETINFO;
1756 qctl.qc_type = UGQUOTA;
1759 while ((c = getopt_long(argc, argv, "b:gi:tu", long_opts, NULL)) != -1) {
1763 if (qctl.qc_type != UGQUOTA) {
1764 fprintf(stderr, "error: -u and -g can't be used "
1765 "more than once\n");
1768 qctl.qc_type = (c == 'u') ? USRQUOTA : GRPQUOTA;
1771 if ((dqi->dqi_bgrace = str2sec(optarg)) == ULONG_MAX) {
1772 fprintf(stderr, "error: bad block-grace: %s\n",
1776 dqb->dqb_valid |= QIF_BTIME;
1779 if ((dqi->dqi_igrace = str2sec(optarg)) == ULONG_MAX) {
1780 fprintf(stderr, "error: bad inode-grace: %s\n",
1784 dqb->dqb_valid |= QIF_ITIME;
1786 case 't': /* Yes, of course! */
1788 default: /* getopt prints error message for us when opterr != 0 */
1793 if (qctl.qc_type == UGQUOTA) {
1794 fprintf(stderr, "error: neither -u nor -g specified\n");
1798 if (optind != argc - 1) {
1799 fprintf(stderr, "error: unexpected parameters encountered\n");
1804 rc = llapi_quotactl(mnt, &qctl);
1807 fprintf(stderr, "%s %s ", obd_type,
1808 obd_uuid2str(&qctl.obd_uuid));
1809 fprintf(stderr, "setquota failed: %s\n", strerror(-rc));
1816 #define BSLIMIT (1 << 0)
1817 #define BHLIMIT (1 << 1)
1818 #define ISLIMIT (1 << 2)
1819 #define IHLIMIT (1 << 3)
1821 int lfs_setquota(int argc, char **argv)
1824 struct if_quotactl qctl;
1825 char *mnt, *obd_type = (char *)qctl.obd_type;
1826 struct obd_dqblk *dqb = &qctl.qc_dqblk;
1827 struct option long_opts[] = {
1828 {"block-softlimit", required_argument, 0, 'b'},
1829 {"block-hardlimit", required_argument, 0, 'B'},
1830 {"group", required_argument, 0, 'g'},
1831 {"inode-softlimit", required_argument, 0, 'i'},
1832 {"inode-hardlimit", required_argument, 0, 'I'},
1833 {"user", required_argument, 0, 'u'},
1836 unsigned limit_mask = 0;
1839 if (has_times_option(argc, argv))
1840 return lfs_setquota_times(argc, argv);
1842 memset(&qctl, 0, sizeof(qctl));
1843 qctl.qc_cmd = LUSTRE_Q_SETQUOTA;
1844 qctl.qc_type = UGQUOTA; /* UGQUOTA makes no sense for setquota,
1845 * so it can be used as a marker that qc_type
1846 * isn't reinitialized from command line */
1849 while ((c = getopt_long(argc, argv, "b:B:g:i:I:u:", long_opts, NULL)) != -1) {
1853 if (qctl.qc_type != UGQUOTA) {
1854 fprintf(stderr, "error: -u and -g can't be used"
1855 " more than once\n");
1858 qctl.qc_type = (c == 'u') ? USRQUOTA : GRPQUOTA;
1859 rc = name2id(&qctl.qc_id, optarg,
1860 (qctl.qc_type == USRQUOTA) ? USER : GROUP);
1862 qctl.qc_id = strtoul(optarg, &endptr, 10);
1863 if (*endptr != '\0') {
1864 fprintf(stderr, "error: can't find id "
1865 "for name %s\n", optarg);
1871 ARG2ULL(dqb->dqb_bsoftlimit, optarg, 1024);
1872 dqb->dqb_bsoftlimit >>= 10;
1873 limit_mask |= BSLIMIT;
1876 ARG2ULL(dqb->dqb_bhardlimit, optarg, 1024);
1877 dqb->dqb_bhardlimit >>= 10;
1878 limit_mask |= BHLIMIT;
1881 ARG2ULL(dqb->dqb_isoftlimit, optarg, 1);
1882 limit_mask |= ISLIMIT;
1885 ARG2ULL(dqb->dqb_ihardlimit, optarg, 1);
1886 limit_mask |= IHLIMIT;
1888 default: /* getopt prints error message for us when opterr != 0 */
1893 if (qctl.qc_type == UGQUOTA) {
1894 fprintf(stderr, "error: neither -u nor -g was specified\n");
1898 if (limit_mask == 0) {
1899 fprintf(stderr, "error: at least one limit must be specified\n");
1903 if (optind != argc - 1) {
1904 fprintf(stderr, "error: unexpected parameters encountered\n");
1910 if ((!(limit_mask & BHLIMIT) ^ !(limit_mask & BSLIMIT)) ||
1911 (!(limit_mask & IHLIMIT) ^ !(limit_mask & ISLIMIT))) {
1912 /* sigh, we can't just set blimits/ilimits */
1913 struct if_quotactl tmp_qctl = {.qc_cmd = LUSTRE_Q_GETQUOTA,
1914 .qc_type = qctl.qc_type,
1915 .qc_id = qctl.qc_id};
1917 rc = llapi_quotactl(mnt, &tmp_qctl);
1919 fprintf(stderr, "error: setquota failed while retrieving"
1920 " current quota settings (%s)\n",
1925 if (!(limit_mask & BHLIMIT))
1926 dqb->dqb_bhardlimit = tmp_qctl.qc_dqblk.dqb_bhardlimit;
1927 if (!(limit_mask & BSLIMIT))
1928 dqb->dqb_bsoftlimit = tmp_qctl.qc_dqblk.dqb_bsoftlimit;
1929 if (!(limit_mask & IHLIMIT))
1930 dqb->dqb_ihardlimit = tmp_qctl.qc_dqblk.dqb_ihardlimit;
1931 if (!(limit_mask & ISLIMIT))
1932 dqb->dqb_isoftlimit = tmp_qctl.qc_dqblk.dqb_isoftlimit;
1934 /* Keep grace times if we have got no softlimit arguments */
1935 if ((limit_mask & BHLIMIT) && !(limit_mask & BSLIMIT)) {
1936 dqb->dqb_valid |= QIF_BTIME;
1937 dqb->dqb_btime = tmp_qctl.qc_dqblk.dqb_btime;
1940 if ((limit_mask & IHLIMIT) && !(limit_mask & ISLIMIT)) {
1941 dqb->dqb_valid |= QIF_ITIME;
1942 dqb->dqb_itime = tmp_qctl.qc_dqblk.dqb_itime;
1946 dqb->dqb_valid |= (limit_mask & (BHLIMIT | BSLIMIT)) ? QIF_BLIMITS : 0;
1947 dqb->dqb_valid |= (limit_mask & (IHLIMIT | ISLIMIT)) ? QIF_ILIMITS : 0;
1949 rc = llapi_quotactl(mnt, &qctl);
1952 fprintf(stderr, "%s %s ", obd_type,
1953 obd_uuid2str(&qctl.obd_uuid));
1954 fprintf(stderr, "setquota failed: %s\n", strerror(-rc));
1961 static inline char *type2name(int check_type)
1963 if (check_type == USRQUOTA)
1965 else if (check_type == GRPQUOTA)
1971 /* Converts seconds value into format string
1972 * result is returned in buf
1974 * 1. result is in descenting order: 1w2d3h4m5s
1975 * 2. zero fields are not filled (except for p. 3): 5d1s
1976 * 3. zero seconds value is presented as "0s"
1978 static char * __sec2str(time_t seconds, char *buf)
1980 const char spec[] = "smhdw";
1981 const unsigned long mult[] = {1, 60, 60*60, 24*60*60, 7*24*60*60};
1986 for (i = sizeof(mult) / sizeof(mult[0]) - 1 ; i >= 0; i--) {
1987 c = seconds / mult[i];
1989 if (c > 0 || (i == 0 && buf == tail))
1990 tail += snprintf(tail, 40-(tail-buf), "%lu%c", c, spec[i]);
1998 static void sec2str(time_t seconds, char *buf, int rc)
2005 tail = __sec2str(seconds, tail);
2007 if (rc && tail - buf < 39) {
2013 static void diff2str(time_t seconds, char *buf, time_t now)
2019 if (seconds <= now) {
2020 strcpy(buf, "none");
2023 __sec2str(seconds - now, buf);
2026 static void print_quota_title(char *name, struct if_quotactl *qctl)
2028 printf("Disk quotas for %s %s (%cid %u):\n",
2029 type2name(qctl->qc_type), name,
2030 *type2name(qctl->qc_type), qctl->qc_id);
2031 printf("%15s%8s %7s%8s%8s%8s %7s%8s%8s\n",
2033 "kbytes", "quota", "limit", "grace",
2034 "files", "quota", "limit", "grace");
2037 static void print_quota(char *mnt, struct if_quotactl *qctl, int type, int rc)
2043 if (qctl->qc_cmd == LUSTRE_Q_GETQUOTA || qctl->qc_cmd == Q_GETOQUOTA) {
2044 int bover = 0, iover = 0;
2045 struct obd_dqblk *dqb = &qctl->qc_dqblk;
2047 if (dqb->dqb_bhardlimit &&
2048 toqb(dqb->dqb_curspace) >= dqb->dqb_bhardlimit) {
2050 } else if (dqb->dqb_bsoftlimit && dqb->dqb_btime) {
2051 if (dqb->dqb_btime > now) {
2058 if (dqb->dqb_ihardlimit &&
2059 dqb->dqb_curinodes >= dqb->dqb_ihardlimit) {
2061 } else if (dqb->dqb_isoftlimit && dqb->dqb_itime) {
2062 if (dqb->dqb_btime > now) {
2069 #if 0 /* XXX: always print quotas even when no usages */
2070 if (dqb->dqb_curspace || dqb->dqb_curinodes)
2076 if (strlen(mnt) > 15)
2077 printf("%s\n%15s", mnt, "");
2079 printf("%15s", mnt);
2082 diff2str(dqb->dqb_btime, timebuf, now);
2083 if (rc == -EREMOTEIO)
2084 sprintf(numbuf[0], LPU64"*",
2085 toqb(dqb->dqb_curspace));
2088 (dqb->dqb_valid & QIF_SPACE) ?
2089 LPU64 : "["LPU64"]",
2090 toqb(dqb->dqb_curspace));
2091 if (type == QC_GENERAL)
2092 sprintf(numbuf[1], (dqb->dqb_valid & QIF_BLIMITS)
2093 ? LPU64 : "["LPU64"]",
2094 dqb->dqb_bsoftlimit);
2096 sprintf(numbuf[1], "%s", "-");
2097 sprintf(numbuf[2], (dqb->dqb_valid & QIF_BLIMITS)
2098 ? LPU64 : "["LPU64"]", dqb->dqb_bhardlimit);
2099 printf(" %7s%c %6s %7s %7s",
2100 numbuf[0], bover ? '*' : ' ', numbuf[1],
2101 numbuf[2], bover > 1 ? timebuf : "-");
2104 diff2str(dqb->dqb_itime, timebuf, now);
2106 sprintf(numbuf[0], (dqb->dqb_valid & QIF_INODES) ?
2107 LPU64 : "["LPU64"]", dqb->dqb_curinodes);
2108 if (type == QC_GENERAL)
2109 sprintf(numbuf[1], (dqb->dqb_valid & QIF_ILIMITS)
2110 ? LPU64 : "["LPU64"]",
2111 dqb->dqb_isoftlimit);
2113 sprintf(numbuf[1], "%s", "-");
2114 sprintf(numbuf[2], (dqb->dqb_valid & QIF_ILIMITS) ?
2115 LPU64 : "["LPU64"]", dqb->dqb_ihardlimit);
2116 if (type != QC_OSTIDX)
2117 printf(" %7s%c %6s %7s %7s",
2118 numbuf[0], iover ? '*' : ' ', numbuf[1],
2119 numbuf[2], iover > 1 ? timebuf : "-");
2121 printf(" %7s %7s %7s %7s", "-", "-", "-", "-");
2124 } else if (qctl->qc_cmd == LUSTRE_Q_GETINFO ||
2125 qctl->qc_cmd == Q_GETOINFO) {
2129 sec2str(qctl->qc_dqinfo.dqi_bgrace, bgtimebuf, rc);
2130 sec2str(qctl->qc_dqinfo.dqi_igrace, igtimebuf, rc);
2131 printf("Block grace time: %s; Inode grace time: %s\n",
2132 bgtimebuf, igtimebuf);
2136 static int print_obd_quota(char *mnt, struct if_quotactl *qctl, int is_mdt)
2138 int rc = 0, rc1 = 0, count = 0;
2139 __u32 valid = qctl->qc_valid;
2141 rc = llapi_get_obd_count(mnt, &count, is_mdt);
2143 fprintf(stderr, "can not get %s count: %s\n",
2144 is_mdt ? "mdt": "ost", strerror(-rc));
2148 for (qctl->qc_idx = 0; qctl->qc_idx < count; qctl->qc_idx++) {
2149 qctl->qc_valid = is_mdt ? QC_MDTIDX : QC_OSTIDX;
2150 rc = llapi_quotactl(mnt, qctl);
2152 /* It is remote client case. */
2153 if (-rc == EOPNOTSUPP) {
2160 fprintf(stderr, "quotactl %s%d failed.\n",
2161 is_mdt ? "mdt": "ost", qctl->qc_idx);
2165 print_quota(obd_uuid2str(&qctl->obd_uuid), qctl, qctl->qc_valid, 0);
2169 qctl->qc_valid = valid;
2173 static int lfs_quota(int argc, char **argv)
2176 char *mnt, *name = NULL;
2177 struct if_quotactl qctl = { .qc_cmd = LUSTRE_Q_GETQUOTA,
2178 .qc_type = UGQUOTA };
2179 char *obd_type = (char *)qctl.obd_type;
2180 char *obd_uuid = (char *)qctl.obd_uuid.uuid;
2181 int rc, rc1 = 0, rc2 = 0, rc3 = 0,
2182 verbose = 0, pass = 0, quiet = 0, inacc;
2184 __u32 valid = QC_GENERAL, idx = 0;
2187 while ((c = getopt(argc, argv, "gi:I:o:qtuv")) != -1) {
2190 if (qctl.qc_type != UGQUOTA) {
2191 fprintf(stderr, "error: use either -u or -g\n");
2194 qctl.qc_type = USRQUOTA;
2197 if (qctl.qc_type != UGQUOTA) {
2198 fprintf(stderr, "error: use either -u or -g\n");
2201 qctl.qc_type = GRPQUOTA;
2204 qctl.qc_cmd = LUSTRE_Q_GETINFO;
2207 valid = qctl.qc_valid = QC_UUID;
2208 strncpy(obd_uuid, optarg, sizeof(qctl.obd_uuid));
2211 valid = qctl.qc_valid = QC_MDTIDX;
2212 idx = qctl.qc_idx = atoi(optarg);
2215 valid = qctl.qc_valid = QC_OSTIDX;
2216 idx = qctl.qc_idx = atoi(optarg);
2225 fprintf(stderr, "error: %s: option '-%c' "
2226 "unrecognized\n", argv[0], c);
2231 /* current uid/gid info for "lfs quota /path/to/lustre/mount" */
2232 if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA && qctl.qc_type == UGQUOTA &&
2233 optind == argc - 1) {
2235 memset(&qctl, 0, sizeof(qctl)); /* spoiled by print_*_quota */
2236 qctl.qc_cmd = LUSTRE_Q_GETQUOTA;
2237 qctl.qc_valid = valid;
2240 qctl.qc_type = USRQUOTA;
2241 qctl.qc_id = geteuid();
2243 qctl.qc_type = GRPQUOTA;
2244 qctl.qc_id = getegid();
2246 rc = id2name(&name, qctl.qc_id,
2247 (qctl.qc_type == USRQUOTA) ? USER : GROUP);
2250 /* lfs quota -u username /path/to/lustre/mount */
2251 } else if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) {
2252 /* options should be followed by u/g-name and mntpoint */
2253 if (optind + 2 != argc || qctl.qc_type == UGQUOTA) {
2254 fprintf(stderr, "error: missing quota argument(s)\n");
2258 name = argv[optind++];
2259 rc = name2id(&qctl.qc_id, name,
2260 (qctl.qc_type == USRQUOTA) ? USER : GROUP);
2262 qctl.qc_id = strtoul(name, &endptr, 10);
2263 if (*endptr != '\0') {
2264 fprintf(stderr, "error: can't find id for name "
2269 } else if (optind + 1 != argc || qctl.qc_type == UGQUOTA) {
2270 fprintf(stderr, "error: missing quota info argument(s)\n");
2276 rc1 = llapi_quotactl(mnt, &qctl);
2280 fprintf(stderr, "%s quotas are not enabled.\n",
2281 qctl.qc_type == USRQUOTA ? "user" : "group");
2284 fprintf(stderr, "Permission denied.\n");
2286 /* We already got a "No such file..." message. */
2289 fprintf(stderr, "Unexpected quotactl error: %s\n",
2294 if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA && !quiet)
2295 print_quota_title(name, &qctl);
2297 if (rc1 && *obd_type)
2298 fprintf(stderr, "%s %s ", obd_type, obd_uuid);
2300 if (qctl.qc_valid != QC_GENERAL)
2303 inacc = (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) &&
2304 ((qctl.qc_dqblk.dqb_valid&(QIF_LIMITS|QIF_USAGE))!=(QIF_LIMITS|QIF_USAGE));
2306 print_quota(mnt, &qctl, QC_GENERAL, rc1);
2308 if (qctl.qc_valid == QC_GENERAL && qctl.qc_cmd != LUSTRE_Q_GETINFO && verbose) {
2309 rc2 = print_obd_quota(mnt, &qctl, 1);
2310 rc3 = print_obd_quota(mnt, &qctl, 0);
2313 if (rc1 || rc2 || rc3 || inacc)
2314 printf("Some errors happened when getting quota info. "
2315 "Some devices may be not working or deactivated. "
2316 "The data in \"[]\" is inaccurate.\n");
2324 #endif /* HAVE_SYS_QUOTA_H! */
2326 static int flushctx_ioctl(char *mp)
2330 fd = open(mp, O_RDONLY);
2332 fprintf(stderr, "flushctx: error open %s: %s\n",
2333 mp, strerror(errno));
2337 rc = ioctl(fd, LL_IOC_FLUSHCTX);
2339 fprintf(stderr, "flushctx: error ioctl %s: %s\n",
2340 mp, strerror(errno));
2346 static int lfs_flushctx(int argc, char **argv)
2348 int kdestroy = 0, c;
2350 char procline[PATH_MAX], *line;
2354 while ((c = getopt(argc, argv, "k")) != -1) {
2360 fprintf(stderr, "error: %s: option '-%c' "
2361 "unrecognized\n", argv[0], c);
2368 if ((rc = system("kdestroy > /dev/null")) != 0) {
2369 rc = WEXITSTATUS(rc);
2370 fprintf(stderr, "error destroying tickets: %d, continuing\n", rc);
2374 if (optind >= argc) {
2375 /* flush for all mounted lustre fs. */
2376 proc = fopen("/proc/mounts", "r");
2378 fprintf(stderr, "error: %s: can't open /proc/mounts\n",
2383 while ((line = fgets(procline, PATH_MAX, proc)) != NULL) {
2388 if (sscanf(line, "%s %s %s", dev, mp, fs) != 3) {
2389 fprintf(stderr, "%s: unexpected format in "
2396 if (strcmp(fs, "lustre") != 0)
2398 /* we use '@' to determine it's a client. are there
2399 * any other better way?
2401 if (strchr(dev, '@') == NULL)
2404 if (flushctx_ioctl(mp))
2408 /* flush fs as specified */
2409 while (optind < argc) {
2410 if (flushctx_ioctl(argv[optind++]))
2421 static int lfs_lsetfacl(int argc, char **argv)
2424 return(llapi_lsetfacl(argc, argv));
2427 static int lfs_lgetfacl(int argc, char **argv)
2430 return(llapi_lgetfacl(argc, argv));
2433 static int lfs_rsetfacl(int argc, char **argv)
2436 return(llapi_rsetfacl(argc, argv));
2439 static int lfs_rgetfacl(int argc, char **argv)
2442 return(llapi_rgetfacl(argc, argv));
2445 static int lfs_cp(int argc, char **argv)
2447 return(llapi_cp(argc, argv));
2450 static int lfs_ls(int argc, char **argv)
2452 return(llapi_ls(argc, argv));
2455 static int lfs_changelog(int argc, char **argv)
2457 void *changelog_priv;
2458 struct changelog_ext_rec *rec;
2459 long long startrec = 0, endrec = 0;
2461 struct option long_opts[] = {
2462 {"follow", no_argument, 0, 'f'},
2465 char short_opts[] = "f";
2469 while ((rc = getopt_long(argc, argv, short_opts,
2470 long_opts, NULL)) != -1) {
2478 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
2479 argv[0], argv[optind - 1]);
2486 mdd = argv[optind++];
2488 startrec = strtoll(argv[optind++], NULL, 10);
2490 endrec = strtoll(argv[optind++], NULL, 10);
2492 rc = llapi_changelog_start(&changelog_priv,
2493 CHANGELOG_FLAG_BLOCK |
2494 (follow ? CHANGELOG_FLAG_FOLLOW : 0),
2497 fprintf(stderr, "Can't start changelog: %s\n",
2498 strerror(errno = -rc));
2502 while ((rc = llapi_changelog_recv(changelog_priv, &rec)) == 0) {
2506 if (endrec && rec->cr_index > endrec) {
2507 llapi_changelog_free(&rec);
2510 if (rec->cr_index < startrec) {
2511 llapi_changelog_free(&rec);
2515 secs = rec->cr_time >> 30;
2516 gmtime_r(&secs, &ts);
2517 printf(LPU64" %02d%-5s %02d:%02d:%02d.%06d %04d.%02d.%02d "
2518 "0x%x t="DFID, rec->cr_index, rec->cr_type,
2519 changelog_type2str(rec->cr_type),
2520 ts.tm_hour, ts.tm_min, ts.tm_sec,
2521 (int)(rec->cr_time & ((1<<30) - 1)),
2522 ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday,
2523 rec->cr_flags & CLF_FLAGMASK, PFID(&rec->cr_tfid));
2524 if (rec->cr_namelen)
2525 /* namespace rec includes parent and filename */
2526 printf(" p="DFID" %.*s", PFID(&rec->cr_pfid),
2527 rec->cr_namelen, rec->cr_name);
2528 if (fid_is_sane(&rec->cr_sfid))
2529 printf(" s="DFID" sp="DFID" %.*s",
2530 PFID(&rec->cr_sfid), PFID(&rec->cr_spfid),
2531 changelog_rec_snamelen(rec),
2532 changelog_rec_sname(rec));
2535 llapi_changelog_free(&rec);
2538 llapi_changelog_fini(&changelog_priv);
2541 fprintf(stderr, "Changelog: %s\n", strerror(errno = -rc));
2543 return (rc == 1 ? 0 : rc);
2546 static int lfs_changelog_clear(int argc, char **argv)
2554 endrec = strtoll(argv[3], NULL, 10);
2556 rc = llapi_changelog_clear(argv[1], argv[2], endrec);
2558 fprintf(stderr, "%s error: %s\n", argv[0],
2559 strerror(errno = -rc));
2563 static int lfs_fid2path(int argc, char **argv)
2565 struct option long_opts[] = {
2566 {"cur", no_argument, 0, 'c'},
2567 {"link", required_argument, 0, 'l'},
2568 {"rec", required_argument, 0, 'r'},
2571 char short_opts[] = "cl:r:";
2572 char *device, *fid, *path;
2573 long long recno = -1;
2581 while ((rc = getopt_long(argc, argv, short_opts,
2582 long_opts, NULL)) != -1) {
2588 linkno = strtol(optarg, NULL, 10);
2591 recno = strtoll(optarg, NULL, 10);
2596 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
2597 argv[0], argv[optind - 1]);
2601 device = argv[optind++];
2602 fid = argv[optind++];
2606 path = calloc(1, PATH_MAX);
2608 lnktmp = (linkno >= 0) ? linkno : 0;
2610 int oldtmp = lnktmp;
2611 long long rectmp = recno;
2612 rc = llapi_fid2path(device, fid, path, PATH_MAX, &rectmp,
2615 fprintf(stderr, "%s error: %s\n", argv[0],
2616 strerror(errno = -rc));
2621 fprintf(stdout, "%lld ", rectmp);
2622 if (device[0] == '/') {
2623 fprintf(stdout, "%s", device);
2624 if (device[strlen(device) - 1] != '/')
2625 fprintf(stdout, "/");
2626 } else if (path[0] == '\0') {
2627 fprintf(stdout, "/");
2629 fprintf(stdout, "%s\n", path);
2632 /* specified linkno */
2634 if (oldtmp == lnktmp)
2643 static int lfs_path2fid(int argc, char **argv)
2653 rc = llapi_path2fid(path, &fid);
2655 fprintf(stderr, "can't get fid for %s: %s\n", path,
2656 strerror(errno = -rc));
2660 printf(DFID"\n", PFID(&fid));
2665 static int lfs_data_version(int argc, char **argv)
2678 while ((c = getopt(argc, argv, "n")) != -1) {
2681 nolock = LL_DV_NOFLUSH;
2690 path = argv[optind];
2691 fd = open(path, O_RDONLY);
2693 fprintf(stderr, "can't open %s: %s\n", path,
2698 rc = llapi_get_data_version(fd, &data_version, nolock);
2700 fprintf(stderr, "can't get version for %s: %s\n", path,
2701 strerror(errno = -rc));
2703 printf(LPU64 "\n", data_version);
2710 int main(int argc, char **argv)
2716 ptl_initialize(argc, argv);
2717 if (obd_initialize(argc, argv) < 0)
2720 Parser_init("lfs > ", cmdlist);
2723 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
2725 rc = Parser_commands();
2728 obd_finalize(argc, argv);
2729 return rc < 0 ? -rc : rc;