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, 2013, Intel Corporation.
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/lnetctl.h>
71 #include <liblustre.h>
72 #include <lustre/lustreapi.h>
74 #include <libcfs/libcfsutil.h>
80 static int lfs_setstripe(int argc, char **argv);
81 static int lfs_find(int argc, char **argv);
82 static int lfs_getstripe(int argc, char **argv);
83 static int lfs_getdirstripe(int argc, char **argv);
84 static int lfs_setdirstripe(int argc, char **argv);
85 static int lfs_rmentry(int argc, char **argv);
86 static int lfs_osts(int argc, char **argv);
87 static int lfs_mdts(int argc, char **argv);
88 static int lfs_df(int argc, char **argv);
89 static int lfs_getname(int argc, char **argv);
90 static int lfs_check(int argc, char **argv);
91 #ifdef HAVE_SYS_QUOTA_H
92 static int lfs_quotacheck(int argc, char **argv);
93 static int lfs_quotaon(int argc, char **argv);
94 static int lfs_quotaoff(int argc, char **argv);
95 static int lfs_setquota(int argc, char **argv);
96 static int lfs_quota(int argc, char **argv);
98 static int lfs_flushctx(int argc, char **argv);
99 static int lfs_join(int argc, char **argv);
100 static int lfs_lsetfacl(int argc, char **argv);
101 static int lfs_lgetfacl(int argc, char **argv);
102 static int lfs_rsetfacl(int argc, char **argv);
103 static int lfs_rgetfacl(int argc, char **argv);
104 static int lfs_cp(int argc, char **argv);
105 static int lfs_ls(int argc, char **argv);
106 static int lfs_poollist(int argc, char **argv);
107 static int lfs_changelog(int argc, char **argv);
108 static int lfs_changelog_clear(int argc, char **argv);
109 static int lfs_fid2path(int argc, char **argv);
110 static int lfs_path2fid(int argc, char **argv);
111 static int lfs_data_version(int argc, char **argv);
112 static int lfs_hsm_state(int argc, char **argv);
113 static int lfs_hsm_set(int argc, char **argv);
114 static int lfs_hsm_clear(int argc, char **argv);
115 static int lfs_hsm_action(int argc, char **argv);
116 static int lfs_hsm_archive(int argc, char **argv);
117 static int lfs_hsm_restore(int argc, char **argv);
118 static int lfs_hsm_release(int argc, char **argv);
119 static int lfs_hsm_remove(int argc, char **argv);
120 static int lfs_hsm_cancel(int argc, char **argv);
121 static int lfs_swap_layouts(int argc, char **argv);
123 #define SETSTRIPE_USAGE(_cmd, _tgt) \
124 "usage: "_cmd" [--stripe-count|-c <stripe_count>]\n"\
125 " [--stripe-index|-i <start_ost_idx>]\n"\
126 " [--stripe-size|-S <stripe_size>]\n"\
127 " [--pool|-p <pool_name>]\n"\
128 " [--block|-b] "_tgt"\n"\
129 "\tstripe_size: Number of bytes on each OST (0 filesystem default)\n"\
130 "\t Can be specified with k, m or g (in KB, MB and GB\n"\
131 "\t respectively)\n"\
132 "\tstart_ost_idx: OST index of first stripe (-1 default)\n"\
133 "\tstripe_count: Number of OSTs to stripe over (0 default, -1 all)\n"\
134 "\tpool_name: Name of OST pool to use (default none)\n"\
135 "\tblock: Block file access during data migration"
137 /* all avaialable commands */
138 command_t cmdlist[] = {
139 {"setstripe", lfs_setstripe, 0,
140 "Create a new file with a specific striping pattern or\n"
141 "set the default striping pattern on an existing directory or\n"
142 "delete the default striping pattern from an existing directory\n"
143 "usage: setstripe -d <directory> (to delete default striping)\n"\
145 SETSTRIPE_USAGE("setstripe", "<directory|filename>")},
146 {"getstripe", lfs_getstripe, 0,
147 "To list the striping info for a given file or files in a\n"
148 "directory or recursively for all files in a directory tree.\n"
149 "usage: getstripe [--ost|-O <uuid>] [--quiet | -q] [--verbose | -v]\n"
150 " [--stripe-count|-c] [--stripe-index|-i]\n"
151 " [--pool|-p] [--stripe-size|-S] [--directory|-d]\n"
152 " [--mdt-index|-M] [--recursive|-r] [--raw|-R]\n"
154 " <directory|filename> ..."},
155 {"setdirstripe", lfs_setdirstripe, 0,
156 "To create a remote directory on a specified MDT.\n"
157 "usage: setdirstripe <--index|-i mdt_index> <dir>\n"
158 "\tmdt_index: MDT index of first stripe\n"},
159 {"getdirstripe", lfs_getdirstripe, 0,
160 "To list the striping info for a given directory\n"
161 "or recursively for all directories in a directory tree.\n"
162 "usage: getdirstripe [--obd|-O <uuid>] [--quiet|-q] [--verbose|-v]\n"
163 " [--count|-c ] [--index|-i ] [--raw|-R]\n"
164 " [--recursive | -r] <dir> ..."},
165 {"mkdir", lfs_setdirstripe, 0,
166 "To create a remote directory on a specified MDT. And this can only\n"
167 "be done on MDT0 by administrator.\n"
168 "usage: mkdir <--index|-i mdt_index> <dir>\n"
169 "\tmdt_index: MDT index of the remote directory.\n"},
170 {"rm_entry", lfs_rmentry, 0,
171 "To remove the name entry of the remote directory. Note: This\n"
172 "command will only delete the name entry, i.e. the remote directory\n"
173 "will become inaccessable after this command. This can only be done\n"
174 "by the administrator\n"
175 "usage: rm_entry <dir>\n"},
176 {"pool_list", lfs_poollist, 0,
177 "List pools or pool OSTs\n"
178 "usage: pool_list <fsname>[.<pool>] | <pathname>\n"},
179 {"find", lfs_find, 0,
180 "find files matching given attributes recursively in directory tree.\n"
181 "usage: find <directory|filename> ...\n"
182 " [[!] --atime|-A [+-]N] [[!] --ctime|-C [+-]N]\n"
183 " [[!] --mtime|-M [+-]N] [[!] --mdt|-m <uuid|index,...>]\n"
184 " [--maxdepth|-D N] [[!] --name|-n <pattern>]\n"
185 " [[!] --ost|-O <uuid|index,...>] [--print|-p] [--print0|-P]\n"
186 " [[!] --size|-s [+-]N[bkMGTPE]]\n"
187 " [[!] --stripe-count|-c [+-]<stripes>]\n"
188 " [[!] --stripe-index|-i <index,...>]\n"
189 " [[!] --stripe-size|-S [+-]N[kMGT]] [[!] --type|-t <filetype>]\n"
190 " [[!] --gid|-g|--group|-G <gid>|<gname>]\n"
191 " [[!] --uid|-u|--user|-U <uid>|<uname>] [[!] --pool <pool>]\n"
192 " [[!] --layout|-L released,raid0]\n"
193 "\t !: used before an option indicates 'NOT' requested attribute\n"
194 "\t -: used before a value indicates 'AT MOST' requested value\n"
195 "\t +: used before a value indicates 'AT LEAST' requested value\n"},
196 {"check", lfs_check, 0,
197 "Display the status of MDS or OSTs (as specified in the command)\n"
198 "or all the servers (MDS and OSTs).\n"
199 "usage: check <osts|mds|servers>"},
200 {"join", lfs_join, 0,
201 "join two lustre files into one.\n"
202 "obsolete, HEAD does not support it anymore.\n"},
203 {"osts", lfs_osts, 0, "list OSTs connected to client "
204 "[for specified path only]\n" "usage: osts [path]"},
205 {"mdts", lfs_mdts, 0, "list MDTs connected to client "
206 "[for specified path only]\n" "usage: mdts [path]"},
208 "report filesystem disk space usage or inodes usage"
209 "of each MDS and all OSDs or a batch belonging to a specific pool .\n"
210 "Usage: df [-i] [-h] [--lazy|-l] [--pool|-p <fsname>[.<pool>] [path]"},
211 {"getname", lfs_getname, 0, "list instances and specified mount points "
212 "[for specified path only]\n"
213 "Usage: getname [-h]|[path ...] "},
214 #ifdef HAVE_SYS_QUOTA_H
215 {"quotacheck", lfs_quotacheck, 0,
216 "Scan the specified filesystem for disk usage, and create,\n"
217 "or update quota files. Deprecated as of 2.4.0.\n"
218 "usage: quotacheck [ -ug ] <filesystem>"},
219 {"quotaon", lfs_quotaon, 0, "Turn filesystem"
220 " quotas on. Deprecated as of 2.4.0.\n"
221 "usage: quotaon [ -ugf ] <filesystem>"},
222 {"quotaoff", lfs_quotaoff, 0, "Turn filesystem"
223 " quotas off. Deprecated as of 2.4.0.\n"
224 "usage: quotaoff [ -ug ] <filesystem>"},
225 {"setquota", lfs_setquota, 0, "Set filesystem quotas.\n"
226 "usage: setquota <-u|-g> <uname>|<uid>|<gname>|<gid>\n"
227 " -b <block-softlimit> -B <block-hardlimit>\n"
228 " -i <inode-softlimit> -I <inode-hardlimit> <filesystem>\n"
229 " setquota <-u|--user|-g|--group> <uname>|<uid>|<gname>|<gid>\n"
230 " [--block-softlimit <block-softlimit>]\n"
231 " [--block-hardlimit <block-hardlimit>]\n"
232 " [--inode-softlimit <inode-softlimit>]\n"
233 " [--inode-hardlimit <inode-hardlimit>] <filesystem>\n"
234 " setquota [-t] <-u|--user|-g|--group>\n"
235 " [--block-grace <block-grace>]\n"
236 " [--inode-grace <inode-grace>] <filesystem>\n"
237 " -b can be used instead of --block-softlimit/--block-grace\n"
238 " -B can be used instead of --block-hardlimit\n"
239 " -i can be used instead of --inode-softlimit/--inode-grace\n"
240 " -I can be used instead of --inode-hardlimit\n\n"
241 "Note: The total quota space will be split into many qunits and\n"
242 " balanced over all server targets, the minimal qunit size is\n"
243 " 1M bytes for block space and 1K inodes for inode space.\n\n"
244 " Quota space rebalancing process will stop when this mininum\n"
245 " value is reached. As a result, quota exceeded can be returned\n"
246 " while many targets still have 1MB or 1K inodes of spare\n"
248 {"quota", lfs_quota, 0, "Display disk usage and limits.\n"
249 "usage: quota [-q] [-v] [-o <obd_uuid>|-i <mdt_idx>|-I <ost_idx>]\n"
250 " [<-u|-g> <uname>|<uid>|<gname>|<gid>] <filesystem>\n"
251 " quota [-o <obd_uuid>|-i <mdt_idx>|-I <ost_idx>] -t <-u|-g> <filesystem>"},
253 {"flushctx", lfs_flushctx, 0, "Flush security context for current user.\n"
254 "usage: flushctx [-k] [mountpoint...]"},
255 {"lsetfacl", lfs_lsetfacl, 0,
256 "Remote user setfacl for user/group on the same remote client.\n"
257 "usage: lsetfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ..."},
258 {"lgetfacl", lfs_lgetfacl, 0,
259 "Remote user getfacl for user/group on the same remote client.\n"
260 "usage: lgetfacl [-dRLPvh] file ..."},
261 {"rsetfacl", lfs_rsetfacl, 0,
262 "Remote user setfacl for user/group on other clients.\n"
263 "usage: rsetfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ..."},
264 {"rgetfacl", lfs_rgetfacl, 0,
265 "Remote user getfacl for user/group on other clients.\n"
266 "usage: rgetfacl [-dRLPvh] file ..."},
268 "Remote user copy files and directories.\n"
269 "usage: cp [OPTION]... [-T] SOURCE DEST\n\tcp [OPTION]... SOURCE... DIRECTORY\n\tcp [OPTION]... -t DIRECTORY SOURCE..."},
271 "Remote user list directory contents.\n"
272 "usage: ls [OPTION]... [FILE]..."},
273 {"changelog", lfs_changelog, 0,
274 "Show the metadata changes on an MDT."
275 "\nusage: changelog <mdtname> [startrec [endrec]]"},
276 {"changelog_clear", lfs_changelog_clear, 0,
277 "Indicate that old changelog records up to <endrec> are no longer of "
278 "interest to consumer <id>, allowing the system to free up space.\n"
279 "An <endrec> of 0 means all records.\n"
280 "usage: changelog_clear <mdtname> <id> <endrec>"},
281 {"fid2path", lfs_fid2path, 0,
282 "Resolve the full path(s) for given FID(s). For a specific hardlink "
283 "specify link number <linkno>.\n"
284 /* "For a historical link name, specify changelog record <recno>.\n" */
285 "usage: fid2path [--link <linkno>] <fsname|rootpath> <fid> ..."
286 /* [ --rec <recno> ] */ },
287 {"path2fid", lfs_path2fid, 0, "Display the fid(s) for a given path(s).\n"
288 "usage: path2fid <path> ..."},
289 {"data_version", lfs_data_version, 0, "Display file data version for "
290 "a given path.\n" "usage: data_version [-n] <path>"},
291 {"hsm_state", lfs_hsm_state, 0, "Display the HSM information (states, "
292 "undergoing actions) for given files.\n usage: hsm_state <file> ..."},
293 {"hsm_set", lfs_hsm_set, 0, "Set HSM user flag on specified files.\n"
294 "usage: hsm_set [--norelease] [--noarchive] [--dirty] [--exists] "
295 "[--archived] [--lost] <file> ..."},
296 {"hsm_clear", lfs_hsm_clear, 0, "Clear HSM user flag on specified "
298 "usage: hsm_clear [--norelease] [--noarchive] [--dirty] [--exists] "
299 "[--archived] [--lost] <file> ..."},
300 {"hsm_action", lfs_hsm_action, 0, "Display current HSM request for "
301 "given files.\n" "usage: hsm_action <file> ..."},
302 {"hsm_archive", lfs_hsm_archive, 0,
303 "Archive file to external storage.\n"
304 "usage: hsm_archive [--filelist FILELIST] [--data DATA] [--archive NUM] "
306 {"hsm_restore", lfs_hsm_restore, 0,
307 "Restore file from external storage.\n"
308 "usage: hsm_restore [--filelist FILELIST] [--data DATA] <file> ..."},
309 {"hsm_release", lfs_hsm_release, 0,
310 "Release files from Lustre.\n"
311 "usage: hsm_release [--filelist FILELIST] [--data DATA] <file> ..."},
312 {"hsm_remove", lfs_hsm_remove, 0,
313 "Remove file copy from external storage.\n"
314 "usage: hsm_remove [--filelist FILELIST] [--data DATA] <file> ..."},
315 {"hsm_cancel", lfs_hsm_cancel, 0,
316 "Cancel requests related to specified files.\n"
317 "usage: hsm_cancel [--filelist FILELIST] [--data DATA] <file> ..."},
318 {"swap_layouts", lfs_swap_layouts, 0, "Swap layouts between 2 files.\n"
319 "usage: swap_layouts <path1> <path2>"},
320 {"migrate", lfs_setstripe, 0, "migrate file from one layout to "
321 "another (may be not safe with concurent writes).\n"
322 SETSTRIPE_USAGE("migrate ", "<filename>")},
323 {"help", Parser_help, 0, "help"},
324 {"exit", Parser_quit, 0, "quit"},
325 {"quit", Parser_quit, 0, "quit"},
329 static int isnumber(const char *str)
333 if (str[0] != '-' && !isdigit(str[0]))
336 for (ptr = str + 1; *ptr != '\0'; ptr++) {
344 #define MIGRATION_BLOCKS 1
346 static int lfs_migrate(char *name, unsigned long long stripe_size,
347 int stripe_offset, int stripe_count,
348 int stripe_pattern, char *pool_name,
349 __u64 migration_flags)
352 char volatile_file[PATH_MAX];
353 char parent[PATH_MAX];
357 struct lov_user_md *lum = NULL;
362 __u64 rpos, wpos, bufoff;
366 /* find the right size for the IO and allocate the buffer */
367 lumsz = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3);
374 rc = llapi_file_get_stripe(name, lum);
375 /* failure can come from may case and some may be not real error
377 * in case of a real error, a later call will failed with a better
378 * error management */
382 bufsz = lum->lmm_stripe_size;
383 rc = posix_memalign(&buf, getpagesize(), bufsz);
389 if (migration_flags & MIGRATION_BLOCKS) {
390 /* generate a random id for the grouplock */
391 fd = open("/dev/urandom", O_RDONLY);
394 fprintf(stderr, "cannot open /dev/urandom (%s)\n",
399 rc = read(fd, &gid, sz);
403 fprintf(stderr, "cannot read %d bytes from"
404 " /dev/urandom (%s)\n", sz, strerror(-rc));
409 /* search for file directory pathname */
410 strcpy(parent, name);
411 ptr = strrchr(parent, '/');
413 if (getcwd(parent, sizeof(parent)) == NULL) {
423 sprintf(volatile_file, "%s/%s::", parent, LUSTRE_VOLATILE_HDR);
425 /* create, open a volatile file, use caching (ie no directio) */
426 /* exclusive create is not needed because volatile files cannot
427 * conflict on name by construction */
428 fdv = llapi_file_open_pool(volatile_file, O_CREAT | O_WRONLY,
429 0644, stripe_size, stripe_offset,
430 stripe_count, stripe_pattern, pool_name);
433 fprintf(stderr, "cannot create volatile file in %s (%s)\n",
434 parent, strerror(-rc));
438 /* open file, direct io */
439 /* even if the file is only read, WR mode is nedeed to allow
440 * layout swap on fd */
441 fd = open(name, O_RDWR | O_DIRECT);
444 fprintf(stderr, "cannot open %s (%s)\n", name, strerror(-rc));
449 /* get file data version */
450 rc = llapi_get_data_version(fd, &dv1, 0);
452 fprintf(stderr, "cannot get dataversion on %s (%s)\n",
453 name, strerror(-rc));
457 if (migration_flags & MIGRATION_BLOCKS) {
458 /* take group lock to limit concurent access
459 * this will be no more needed when exclusive access will
460 * be implemented (see LU-2919) */
461 /* group lock is taken after data version read because it
462 * blocks data version call */
463 if (ioctl(fd, LL_IOC_GROUP_LOCK, gid) == -1) {
465 fprintf(stderr, "cannot get group lock on %s (%s)\n",
466 name, strerror(-rc));
478 /* read new data only if we have written all
479 * previously read data */
481 rsize = read(fd, buf, bufsz);
484 fprintf(stderr, "read failed on %s"
495 wsize = write(fdv, buf + bufoff, rpos - wpos);
498 fprintf(stderr, "write failed on volatile"
499 " for %s (%s)\n", name, strerror(-rc));
509 if (migration_flags & MIGRATION_BLOCKS) {
510 /* give back group lock */
511 if (ioctl(fd, LL_IOC_GROUP_UNLOCK, gid) == -1) {
513 fprintf(stderr, "cannot put group lock on %s (%s)\n",
514 name, strerror(-rc));
520 * for a migration we need to:
521 * - check data version on file did not change
525 rc = llapi_fswap_layouts(fd, fdv, dv1, 0,
526 SWAP_LAYOUTS_CHECK_DV1 |
527 SWAP_LAYOUTS_KEEP_MTIME |
528 SWAP_LAYOUTS_KEEP_ATIME);
530 fprintf(stderr, "file dataversion for %s has changed"
531 " during copy, migration is aborted\n",
536 fprintf(stderr, "cannot swap layouts between %s and "
537 "a volatile file (%s)\n",
538 name, strerror(-rc));
541 /* give back group lock */
542 if ((migration_flags & MIGRATION_BLOCKS) && have_gl &&
543 (ioctl(fd, LL_IOC_GROUP_UNLOCK, gid) == -1)) {
544 /* we keep in rc the original error */
545 fprintf(stderr, "cannot put group lock on %s (%s)\n",
546 name, strerror(-errno));
560 static int lfs_setstripe(int argc, char **argv)
564 unsigned long long st_size;
565 int st_offset, st_count;
569 char *stripe_size_arg = NULL;
570 char *stripe_off_arg = NULL;
571 char *stripe_count_arg = NULL;
572 char *pool_name_arg = NULL;
573 unsigned long long size_units = 1;
574 int migrate_mode = 0;
575 __u64 migration_flags = 0;
577 struct option long_opts[] = {
578 /* valid only in migrate mode */
579 {"block", no_argument, 0, 'b'},
580 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
581 #warning "remove deprecated --count option"
583 /* This formerly implied "stripe-count", but was explicitly
584 * made "stripe-count" for consistency with other options,
585 * and to separate it from "mdt-count" when DNE arrives. */
586 {"count", required_argument, 0, 'c'},
588 {"stripe-count", required_argument, 0, 'c'},
589 {"stripe_count", required_argument, 0, 'c'},
590 {"delete", no_argument, 0, 'd'},
591 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
592 #warning "remove deprecated --index option"
594 /* This formerly implied "stripe-index", but was explicitly
595 * made "stripe-index" for consistency with other options,
596 * and to separate it from "mdt-index" when DNE arrives. */
597 {"index", required_argument, 0, 'i'},
599 {"stripe-index", required_argument, 0, 'i'},
600 {"stripe_index", required_argument, 0, 'i'},
601 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
602 #warning "remove deprecated --offset option"
604 /* This formerly implied "stripe-index", but was confusing
605 * with "file offset" (which will eventually be needed for
606 * with different layouts by offset), so deprecate it. */
607 {"offset", required_argument, 0, 'o'},
609 {"pool", required_argument, 0, 'p'},
610 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
611 #warning "remove deprecated --size option"
613 /* This formerly implied "--stripe-size", but was confusing
614 * with "lfs find --size|-s", which means "file size", so use
615 * the consistent "--stripe-size|-S" for all commands. */
616 {"size", required_argument, 0, 's'},
618 {"stripe-size", required_argument, 0, 'S'},
619 {"stripe_size", required_argument, 0, 'S'},
627 if (strcmp(argv[0], "migrate") == 0)
630 #if LUSTRE_VERSION < OBD_OCD_VERSION(2,4,50,0)
631 if (argc == 5 && argv[1][0] != '-' &&
632 isnumber(argv[2]) && isnumber(argv[3]) && isnumber(argv[4])) {
633 fprintf(stderr, "error: obsolete usage of setstripe "
634 "positional parameters. Use -c, -i, -S instead.\n");
638 #warning "remove obsolete positional parameter error"
642 while ((c = getopt_long(argc, argv, "c:di:o:p:s:S:",
643 long_opts, NULL)) >= 0) {
649 if (migrate_mode == 0) {
650 fprintf(stderr, "--block is valid only for"
654 migration_flags |= MIGRATION_BLOCKS;
657 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
658 #warning "remove deprecated --count option"
659 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
660 if (strcmp(argv[optind - 1], "--count") == 0)
661 fprintf(stderr, "warning: '--count' deprecated"
662 ", use '--stripe-count' instead\n");
664 stripe_count_arg = optarg;
667 /* delete the default striping pattern */
671 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,4,50,0)
672 fprintf(stderr, "warning: '--offset|-o' deprecated, "
673 "use '--stripe-index|-i' instead\n");
675 if (strcmp(argv[optind - 1], "--offset") == 0)
676 /* need --stripe-index established first */
677 fprintf(stderr, "warning: '--offset' deprecated"
678 ", use '--index' instead\n");
681 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
682 #warning "remove deprecated --offset and --index options"
683 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
684 if (strcmp(argv[optind - 1], "--index") == 0)
685 fprintf(stderr, "warning: '--index' deprecated"
686 ", use '--stripe-index' instead\n");
688 stripe_off_arg = optarg;
691 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
692 #warning "remove deprecated --size option"
693 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
694 fprintf(stderr, "warning: '--size|-s' deprecated, "
695 "use '--stripe-size|-S' instead\n");
698 stripe_size_arg = optarg;
701 pool_name_arg = optarg;
708 fname = argv[optind];
711 (stripe_size_arg != NULL || stripe_off_arg != NULL ||
712 stripe_count_arg != NULL || pool_name_arg != NULL)) {
713 fprintf(stderr, "error: %s: cannot specify -d with "
714 "-s, -c, -o, or -p options\n",
720 if (optind == argc) {
721 fprintf(stderr, "error: %s: missing filename|dirname\n",
726 /* get the stripe size */
727 if (stripe_size_arg != NULL) {
728 result = llapi_parse_size(stripe_size_arg, &st_size,
731 fprintf(stderr, "error: %s: bad stripe size '%s'\n",
732 argv[0], stripe_size_arg);
736 /* get the stripe offset */
737 if (stripe_off_arg != NULL) {
738 st_offset = strtol(stripe_off_arg, &end, 0);
740 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
741 argv[0], stripe_off_arg);
745 /* get the stripe count */
746 if (stripe_count_arg != NULL) {
747 st_count = strtoul(stripe_count_arg, &end, 0);
749 fprintf(stderr, "error: %s: bad stripe count '%s'\n",
750 argv[0], stripe_count_arg);
757 result = lfs_migrate(fname, st_size, st_offset,
758 st_count, 0, pool_name_arg,
761 result = llapi_file_create_pool(fname, st_size,
766 "error: %s: %s stripe file '%s' failed\n",
767 argv[0], migrate_mode ? "migrate" : "create",
771 fname = argv[++optind];
772 } while (fname != NULL);
777 static int lfs_poollist(int argc, char **argv)
782 return llapi_poollist(argv[1]);
785 static int set_time(time_t *time, time_t *set, char *str)
792 else if (str[0] == '-')
798 t = strtol(str, NULL, 0);
799 if (*time < t * 24 * 60 * 60) {
802 fprintf(stderr, "Wrong time '%s' is specified.\n", str);
806 *set = *time - t * 24 * 60 * 60;
813 static int name2id(unsigned int *id, char *name, int type)
816 struct passwd *entry;
818 if (!(entry = getpwnam(name))) {
828 if (!(entry = getgrnam(name))) {
840 static int id2name(char **name, unsigned int id, int type)
843 struct passwd *entry;
845 if (!(entry = getpwuid(id))) {
851 *name = entry->pw_name;
855 if (!(entry = getgrgid(id))) {
861 *name = entry->gr_name;
867 static int name2layout(__u32 *layout, char *name)
872 for (ptr = name; ; ptr = NULL) {
873 lyt = strtok(ptr, ",");
876 if (strcmp(lyt, "released") == 0)
877 *layout |= LOV_PATTERN_F_RELEASED;
878 else if (strcmp(lyt, "raid0") == 0)
879 *layout |= LOV_PATTERN_RAID0;
886 #define FIND_POOL_OPT 3
887 static int lfs_find(int argc, char **argv)
891 struct find_param param = { .maxdepth = -1, .quiet = 1 };
892 struct option long_opts[] = {
893 {"atime", required_argument, 0, 'A'},
894 {"stripe-count", required_argument, 0, 'c'},
895 {"stripe_count", required_argument, 0, 'c'},
896 {"ctime", required_argument, 0, 'C'},
897 {"maxdepth", required_argument, 0, 'D'},
898 {"gid", required_argument, 0, 'g'},
899 {"group", required_argument, 0, 'G'},
900 {"stripe-index", required_argument, 0, 'i'},
901 {"stripe_index", required_argument, 0, 'i'},
902 {"layout", required_argument, 0, 'L'},
903 {"mdt", required_argument, 0, 'm'},
904 {"mtime", required_argument, 0, 'M'},
905 {"name", required_argument, 0, 'n'},
906 /* reserve {"or", no_argument, , 0, 'o'}, to match find(1) */
907 {"obd", required_argument, 0, 'O'},
908 {"ost", required_argument, 0, 'O'},
909 /* no short option for pool, p/P already used */
910 {"pool", required_argument, 0, FIND_POOL_OPT},
911 {"print0", no_argument, 0, 'p'},
912 {"print", no_argument, 0, 'P'},
913 {"size", required_argument, 0, 's'},
914 {"stripe-size", required_argument, 0, 'S'},
915 {"stripe_size", required_argument, 0, 'S'},
916 {"type", required_argument, 0, 't'},
917 {"uid", required_argument, 0, 'u'},
918 {"user", required_argument, 0, 'U'},
932 /* when getopt_long_only() hits '!' it returns 1, puts "!" in optarg */
933 while ((c = getopt_long_only(argc, argv,
934 "-A:c:C:D:g:G:i:L:m:M:n:O:Ppqrs:S:t:u:U:v",
935 long_opts, NULL)) >= 0) {
940 /* '!' is part of option */
941 /* when getopt_long_only() finds a string which is not
942 * an option nor a known option argument it returns 1
943 * in that case if we already have found pathstart and pathend
944 * (i.e. we have the list of pathnames),
945 * the only supported value is "!"
947 isoption = (c != 1) || (strcmp(optarg, "!") == 0);
948 if (!isoption && pathend != -1) {
949 fprintf(stderr, "err: %s: filename|dirname must either "
950 "precede options or follow options\n",
955 if (!isoption && pathstart == -1)
956 pathstart = optind - 1;
957 if (isoption && pathstart != -1 && pathend == -1)
958 pathend = optind - 2;
964 /* unknown; opt is "!" or path component,
965 * checking done above.
967 if (strcmp(optarg, "!") == 0)
971 xtime = ¶m.atime;
972 xsign = ¶m.asign;
973 param.exclude_atime = !!neg_opt;
974 /* no break, this falls through to 'C' for ctime */
977 xtime = ¶m.ctime;
978 xsign = ¶m.csign;
979 param.exclude_ctime = !!neg_opt;
981 /* no break, this falls through to 'M' for mtime */
984 xtime = ¶m.mtime;
985 xsign = ¶m.msign;
986 param.exclude_mtime = !!neg_opt;
988 ret = set_time(&t, xtime, optarg);
989 if (ret == INT_MAX) {
997 if (optarg[0] == '+') {
998 param.stripecount_sign = -1;
1000 } else if (optarg[0] == '-') {
1001 param.stripecount_sign = 1;
1005 param.stripecount = strtoul(optarg, &endptr, 0);
1006 if (*endptr != '\0') {
1007 fprintf(stderr,"error: bad stripe_count '%s'\n",
1012 param.check_stripecount = 1;
1013 param.exclude_stripecount = !!neg_opt;
1016 param.maxdepth = strtol(optarg, 0, 0);
1020 ret = name2id(¶m.gid, optarg, GROUP);
1022 param.gid = strtoul(optarg, &endptr, 10);
1023 if (*endptr != '\0') {
1024 fprintf(stderr, "Group/GID: %s cannot "
1025 "be found.\n", optarg);
1030 param.exclude_gid = !!neg_opt;
1031 param.check_gid = 1;
1034 ret = name2layout(¶m.layout, optarg);
1037 param.exclude_layout = !!neg_opt;
1038 param.check_layout = 1;
1042 ret = name2id(¶m.uid, optarg, USER);
1044 param.uid = strtoul(optarg, &endptr, 10);
1045 if (*endptr != '\0') {
1046 fprintf(stderr, "User/UID: %s cannot "
1047 "be found.\n", optarg);
1052 param.exclude_uid = !!neg_opt;
1053 param.check_uid = 1;
1056 if (strlen(optarg) > LOV_MAXPOOLNAME) {
1058 "Pool name %s is too long"
1059 " (max is %d)\n", optarg,
1064 /* we do check for empty pool because empty pool
1065 * is used to find V1 lov attributes */
1066 strncpy(param.poolname, optarg, LOV_MAXPOOLNAME);
1067 param.poolname[LOV_MAXPOOLNAME] = '\0';
1068 param.exclude_pool = !!neg_opt;
1069 param.check_pool = 1;
1072 param.pattern = (char *)optarg;
1073 param.exclude_pattern = !!neg_opt;
1078 char *buf, *token, *next, *p;
1082 buf = strdup(optarg);
1088 param.exclude_obd = !!neg_opt;
1091 while (token && *token) {
1092 token = strchr(token, ',');
1099 param.exclude_mdt = !!neg_opt;
1100 param.num_alloc_mdts += len;
1101 tmp = realloc(param.mdtuuid,
1102 param.num_alloc_mdts *
1103 sizeof(*param.mdtuuid));
1105 GOTO(err_free, ret = -ENOMEM);
1106 param.mdtuuid = tmp;
1108 param.exclude_obd = !!neg_opt;
1109 param.num_alloc_obds += len;
1110 tmp = realloc(param.obduuid,
1111 param.num_alloc_obds *
1112 sizeof(*param.obduuid));
1114 GOTO(err_free, ret = -ENOMEM);
1115 param.obduuid = tmp;
1117 for (token = buf; token && *token; token = next) {
1121 param.mdtuuid[param.num_mdts++].uuid;
1124 param.obduuid[param.num_obds++].uuid;
1125 p = strchr(token, ',');
1131 strcpy((char *)uuid, token);
1144 if (optarg[0] == '+') {
1145 param.size_sign = -1;
1147 } else if (optarg[0] == '-') {
1148 param.size_sign = 1;
1152 ret = llapi_parse_size(optarg, ¶m.size,
1153 ¶m.size_units, 0);
1155 fprintf(stderr, "error: bad file size '%s'\n",
1159 param.check_size = 1;
1160 param.exclude_size = !!neg_opt;
1163 if (optarg[0] == '+') {
1164 param.stripesize_sign = -1;
1166 } else if (optarg[0] == '-') {
1167 param.stripesize_sign = 1;
1171 ret = llapi_parse_size(optarg, ¶m.stripesize,
1172 ¶m.stripesize_units, 0);
1174 fprintf(stderr, "error: bad stripe_size '%s'\n",
1178 param.check_stripesize = 1;
1179 param.exclude_stripesize = !!neg_opt;
1182 param.exclude_type = !!neg_opt;
1184 case 'b': param.type = S_IFBLK; break;
1185 case 'c': param.type = S_IFCHR; break;
1186 case 'd': param.type = S_IFDIR; break;
1187 case 'f': param.type = S_IFREG; break;
1188 case 'l': param.type = S_IFLNK; break;
1189 case 'p': param.type = S_IFIFO; break;
1190 case 's': param.type = S_IFSOCK; break;
1191 #ifdef S_IFDOOR /* Solaris only */
1192 case 'D': param.type = S_IFDOOR; break;
1194 default: fprintf(stderr, "error: %s: bad type '%s'\n",
1206 if (pathstart == -1) {
1207 fprintf(stderr, "error: %s: no filename|pathname\n",
1211 } else if (pathend == -1) {
1217 ret = llapi_find(argv[pathstart], ¶m);
1218 } while (++pathstart < pathend && !ret);
1221 fprintf(stderr, "error: %s failed for %s.\n",
1222 argv[0], argv[optind - 1]);
1224 if (param.obduuid && param.num_alloc_obds)
1225 free(param.obduuid);
1227 if (param.mdtuuid && param.num_alloc_mdts)
1228 free(param.mdtuuid);
1233 static int lfs_getstripe_internal(int argc, char **argv,
1234 struct find_param *param)
1236 struct option long_opts[] = {
1237 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
1238 #warning "remove deprecated --count option"
1240 /* This formerly implied "stripe-count", but was explicitly
1241 * made "stripe-count" for consistency with other options,
1242 * and to separate it from "mdt-count" when DNE arrives. */
1243 {"count", no_argument, 0, 'c'},
1245 {"stripe-count", no_argument, 0, 'c'},
1246 {"stripe_count", no_argument, 0, 'c'},
1247 {"directory", no_argument, 0, 'd'},
1248 {"generation", no_argument, 0, 'g'},
1249 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
1250 #warning "remove deprecated --index option"
1252 /* This formerly implied "stripe-index", but was explicitly
1253 * made "stripe-index" for consistency with other options,
1254 * and to separate it from "mdt-index" when DNE arrives. */
1255 {"index", no_argument, 0, 'i'},
1257 {"stripe-index", no_argument, 0, 'i'},
1258 {"stripe_index", no_argument, 0, 'i'},
1259 {"layout", no_argument, 0, 'L'},
1260 {"mdt-index", no_argument, 0, 'M'},
1261 {"mdt_index", no_argument, 0, 'M'},
1262 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
1263 #warning "remove deprecated --offset option"
1265 /* This formerly implied "stripe-index", but was confusing
1266 * with "file offset" (which will eventually be needed for
1267 * with different layouts by offset), so deprecate it. */
1268 {"offset", no_argument, 0, 'o'},
1270 {"obd", required_argument, 0, 'O'},
1271 {"ost", required_argument, 0, 'O'},
1272 {"pool", no_argument, 0, 'p'},
1273 {"quiet", no_argument, 0, 'q'},
1274 {"recursive", no_argument, 0, 'r'},
1275 {"raw", no_argument, 0, 'R'},
1276 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
1277 #warning "remove deprecated --size option"
1279 /* This formerly implied "--stripe-size", but was confusing
1280 * with "lfs find --size|-s", which means "file size", so use
1281 * the consistent "--stripe-size|-S" for all commands. */
1282 {"size", no_argument, 0, 's'},
1284 {"stripe-size", no_argument, 0, 'S'},
1285 {"stripe_size", no_argument, 0, 'S'},
1286 {"verbose", no_argument, 0, 'v'},
1291 param->maxdepth = 1;
1293 while ((c = getopt_long(argc, argv, "cdghiLMoO:pqrRsSv",
1294 long_opts, NULL)) != -1) {
1297 if (param->obduuid) {
1299 "error: %s: only one obduuid allowed",
1303 param->obduuid = (struct obd_uuid *)optarg;
1309 param->maxdepth = 0;
1312 param->recursive = 1;
1315 param->verbose = VERBOSE_ALL | VERBOSE_DETAIL;
1318 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
1319 #warning "remove deprecated --count option"
1320 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
1321 if (strcmp(argv[optind - 1], "--count") == 0)
1322 fprintf(stderr, "warning: '--count' deprecated,"
1323 " use '--stripe-count' instead\n");
1325 if (!(param->verbose & VERBOSE_DETAIL)) {
1326 param->verbose |= VERBOSE_COUNT;
1327 param->maxdepth = 0;
1331 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
1332 #warning "remove deprecated --size option"
1333 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
1334 fprintf(stderr, "warning: '--size|-s' deprecated, "
1335 "use '--stripe-size|-S' instead\n");
1338 if (!(param->verbose & VERBOSE_DETAIL)) {
1339 param->verbose |= VERBOSE_SIZE;
1340 param->maxdepth = 0;
1344 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,4,50,0)
1345 fprintf(stderr, "warning: '--offset|-o' deprecated, "
1346 "use '--stripe-index|-i' instead\n");
1348 if (strcmp(argv[optind - 1], "--offset") == 0)
1349 /* need --stripe-index established first */
1350 fprintf(stderr, "warning: '--offset' deprecated"
1351 ", use '--index' instead\n");
1354 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
1355 #warning "remove deprecated --offset and --index options"
1356 #elif LUSTRE_VERSION >= OBD_OCD_VERSION(2,6,50,0)
1357 if (strcmp(argv[optind - 1], "--index") == 0)
1358 fprintf(stderr, "warning: '--index' deprecated"
1359 ", use '--stripe-index' instead\n");
1361 if (!(param->verbose & VERBOSE_DETAIL)) {
1362 param->verbose |= VERBOSE_OFFSET;
1363 param->maxdepth = 0;
1367 if (!(param->verbose & VERBOSE_DETAIL)) {
1368 param->verbose |= VERBOSE_POOL;
1369 param->maxdepth = 0;
1373 if (!(param->verbose & VERBOSE_DETAIL)) {
1374 param->verbose |= VERBOSE_GENERATION;
1375 param->maxdepth = 0;
1379 if (!(param->verbose & VERBOSE_DETAIL)) {
1380 param->verbose |= VERBOSE_LAYOUT;
1381 param->maxdepth = 0;
1385 if (!(param->verbose & VERBOSE_DETAIL))
1386 param->maxdepth = 0;
1387 param->verbose |= VERBOSE_MDTINDEX;
1400 if (param->recursive)
1401 param->maxdepth = -1;
1403 if (!param->verbose)
1404 param->verbose = VERBOSE_ALL;
1406 param->verbose = VERBOSE_OBJID;
1409 rc = llapi_getstripe(argv[optind], param);
1410 } while (++optind < argc && !rc);
1413 fprintf(stderr, "error: %s failed for %s.\n",
1414 argv[0], argv[optind - 1]);
1418 static int lfs_tgts(int argc, char **argv)
1420 char mntdir[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'};
1421 struct find_param param;
1422 int index = 0, rc=0;
1427 if (argc == 2 && !realpath(argv[1], path)) {
1429 fprintf(stderr, "error: invalid path '%s': %s\n",
1430 argv[1], strerror(-rc));
1434 while (!llapi_search_mounts(path, index++, mntdir, NULL)) {
1435 /* Check if we have a mount point */
1436 if (mntdir[0] == '\0')
1439 memset(¶m, 0, sizeof(param));
1440 if (!strcmp(argv[0], "mdts"))
1443 rc = llapi_ostlist(mntdir, ¶m);
1445 fprintf(stderr, "error: %s: failed on %s\n",
1448 if (path[0] != '\0')
1450 memset(mntdir, 0, PATH_MAX);
1456 static int lfs_getstripe(int argc, char **argv)
1458 struct find_param param = { 0 };
1459 return lfs_getstripe_internal(argc, argv, ¶m);
1463 static int lfs_getdirstripe(int argc, char **argv)
1465 struct find_param param = { 0 };
1468 return lfs_getstripe_internal(argc, argv, ¶m);
1472 static int lfs_setdirstripe(int argc, char **argv)
1476 int st_offset, st_count;
1479 char *stripe_off_arg = NULL;
1482 struct option long_opts[] = {
1483 {"index", required_argument, 0, 'i'},
1490 while ((c = getopt_long(argc, argv, "i:o",
1491 long_opts, NULL)) >= 0) {
1497 stripe_off_arg = optarg;
1500 fprintf(stderr, "error: %s: option '%s' "
1502 argv[0], argv[optind - 1]);
1507 if (optind == argc) {
1508 fprintf(stderr, "error: %s: missing dirname\n",
1513 dname = argv[optind];
1514 if (stripe_off_arg == NULL) {
1515 fprintf(stderr, "error: %s: missing stripe_off.\n",
1519 /* get the stripe offset */
1520 st_offset = strtoul(stripe_off_arg, &end, 0);
1522 fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
1523 argv[0], stripe_off_arg);
1527 result = llapi_dir_create_pool(dname, flags, st_offset,
1530 fprintf(stderr, "error: %s: create stripe dir '%s' "
1531 "failed\n", argv[0], dname);
1534 dname = argv[++optind];
1535 } while (dname != NULL);
1541 static int lfs_rmentry(int argc, char **argv)
1548 fprintf(stderr, "error: %s: missing dirname\n",
1554 dname = argv[index];
1555 while (dname != NULL) {
1556 result = llapi_direntry_remove(dname);
1558 fprintf(stderr, "error: %s: remove dir entry '%s' "
1559 "failed\n", argv[0], dname);
1562 dname = argv[++index];
1567 static int lfs_osts(int argc, char **argv)
1569 return lfs_tgts(argc, argv);
1572 static int lfs_mdts(int argc, char **argv)
1574 return lfs_tgts(argc, argv);
1577 #define COOK(value) \
1580 while (value > 1024) { \
1588 #define CDF "%11llu"
1589 #define HDF "%8.1f%c"
1593 static int showdf(char *mntdir, struct obd_statfs *stat,
1594 char *uuid, int ishow, int cooked,
1595 char *type, int index, int rc)
1597 long long avail, used, total;
1599 char *suffix = "KMGTPEZY";
1600 /* Note if we have >2^64 bytes/fs these buffers will need to be grown */
1601 char tbuf[20], ubuf[20], abuf[20], rbuf[20];
1609 avail = stat->os_ffree;
1610 used = stat->os_files - stat->os_ffree;
1611 total = stat->os_files;
1613 int shift = cooked ? 0 : 10;
1615 avail = (stat->os_bavail * stat->os_bsize) >> shift;
1616 used = ((stat->os_blocks - stat->os_bfree) *
1617 stat->os_bsize) >> shift;
1618 total = (stat->os_blocks * stat->os_bsize) >> shift;
1621 if ((used + avail) > 0)
1622 ratio = (double)used / (double)(used + avail);
1628 cook_val = (double)total;
1631 sprintf(tbuf, HDF, cook_val, suffix[i - 1]);
1633 sprintf(tbuf, CDF, total);
1635 cook_val = (double)used;
1638 sprintf(ubuf, HDF, cook_val, suffix[i - 1]);
1640 sprintf(ubuf, CDF, used);
1642 cook_val = (double)avail;
1645 sprintf(abuf, HDF, cook_val, suffix[i - 1]);
1647 sprintf(abuf, CDF, avail);
1649 sprintf(tbuf, CDF, total);
1650 sprintf(ubuf, CDF, used);
1651 sprintf(abuf, CDF, avail);
1654 sprintf(rbuf, RDF, (int)(ratio * 100 + 0.5));
1655 printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s",
1656 uuid, tbuf, ubuf, abuf, rbuf, mntdir);
1658 printf("[%s:%d]\n", type, index);
1664 printf(UUF": inactive device\n", uuid);
1667 printf(UUF": %s\n", uuid, strerror(-rc));
1674 struct ll_stat_type {
1679 static int mntdf(char *mntdir, char *fsname, char *pool, int ishow,
1680 int cooked, int lazy)
1682 struct obd_statfs stat_buf, sum = { .os_bsize = 1 };
1683 struct obd_uuid uuid_buf;
1684 char *poolname = NULL;
1685 struct ll_stat_type types[] = { { LL_STATFS_LMV, "MDT" },
1686 { LL_STATFS_LOV, "OST" },
1688 struct ll_stat_type *tp;
1694 poolname = strchr(pool, '.');
1695 if (poolname != NULL) {
1696 if (strncmp(fsname, pool, strlen(fsname))) {
1697 fprintf(stderr, "filesystem name incorrect\n");
1706 printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s\n",
1707 "UUID", "Inodes", "IUsed", "IFree",
1708 "IUse%", "Mounted on");
1710 printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s\n",
1711 "UUID", cooked ? "bytes" : "1K-blocks",
1712 "Used", "Available", "Use%", "Mounted on");
1714 for (tp = types; tp->st_name != NULL; tp++) {
1715 for (index = 0; ; index++) {
1716 memset(&stat_buf, 0, sizeof(struct obd_statfs));
1717 memset(&uuid_buf, 0, sizeof(struct obd_uuid));
1718 type = lazy ? tp->st_op | LL_STATFS_NODELAY : tp->st_op;
1719 rc = llapi_obd_statfs(mntdir, type, index,
1720 &stat_buf, &uuid_buf);
1724 if (poolname && tp->st_op == LL_STATFS_LOV &&
1725 llapi_search_ost(fsname, poolname,
1726 obd_uuid2str(&uuid_buf)) != 1)
1729 /* the llapi_obd_statfs() call may have returned with
1730 * an error, but if it filled in uuid_buf we will at
1731 * lease use that to print out a message for that OBD.
1732 * If we didn't get anything in the uuid_buf, then fill
1733 * it in so that we can print an error message. */
1734 if (uuid_buf.uuid[0] == '\0')
1735 sprintf(uuid_buf.uuid, "%s%04x",
1736 tp->st_name, index);
1737 showdf(mntdir, &stat_buf, obd_uuid2str(&uuid_buf),
1738 ishow, cooked, tp->st_name, index, rc);
1741 if (tp->st_op == LL_STATFS_LMV) {
1742 sum.os_ffree += stat_buf.os_ffree;
1743 sum.os_files += stat_buf.os_files;
1744 } else /* if (tp->st_op == LL_STATFS_LOV) */ {
1745 sum.os_blocks += stat_buf.os_blocks *
1747 sum.os_bfree += stat_buf.os_bfree *
1749 sum.os_bavail += stat_buf.os_bavail *
1752 } else if (rc == -EINVAL || rc == -EFAULT) {
1759 showdf(mntdir, &sum, "filesystem summary:", ishow, cooked, NULL, 0,0);
1764 static int lfs_df(int argc, char **argv)
1766 char mntdir[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'};
1767 int ishow = 0, cooked = 0;
1769 int c, rc = 0, index = 0;
1770 char fsname[PATH_MAX] = "", *pool_name = NULL;
1771 struct option long_opts[] = {
1772 {"pool", required_argument, 0, 'p'},
1773 {"lazy", 0, 0, 'l'},
1778 while ((c = getopt_long(argc, argv, "hilp:", long_opts, NULL)) != -1) {
1796 if (optind < argc && !realpath(argv[optind], path)) {
1798 fprintf(stderr, "error: invalid path '%s': %s\n",
1799 argv[optind], strerror(-rc));
1803 while (!llapi_search_mounts(path, index++, mntdir, fsname)) {
1804 /* Check if we have a mount point */
1805 if (mntdir[0] == '\0')
1808 rc = mntdf(mntdir, fsname, pool_name, ishow, cooked, lazy);
1809 if (rc || path[0] != '\0')
1811 fsname[0] = '\0'; /* avoid matching in next loop */
1812 mntdir[0] = '\0'; /* avoid matching in next loop */
1818 static int lfs_getname(int argc, char **argv)
1820 char mntdir[PATH_MAX] = "", path[PATH_MAX] = "", fsname[PATH_MAX] = "";
1821 int rc = 0, index = 0, c;
1822 char buf[sizeof(struct obd_uuid)];
1825 while ((c = getopt(argc, argv, "h")) != -1)
1828 if (optind == argc) { /* no paths specified, get all paths. */
1829 while (!llapi_search_mounts(path, index++, mntdir, fsname)) {
1830 rc = llapi_getname(mntdir, buf, sizeof(buf));
1833 "cannot get name for `%s': %s\n",
1834 mntdir, strerror(-rc));
1838 printf("%s %s\n", buf, mntdir);
1840 path[0] = fsname[0] = mntdir[0] = 0;
1842 } else { /* paths specified, only attempt to search these. */
1843 for (; optind < argc; optind++) {
1844 rc = llapi_getname(argv[optind], buf, sizeof(buf));
1847 "cannot get name for `%s': %s\n",
1848 argv[optind], strerror(-rc));
1852 printf("%s %s\n", buf, argv[optind]);
1858 static int lfs_check(int argc, char **argv)
1861 char mntdir[PATH_MAX] = {'\0'};
1870 obd_types[0] = obd_type1;
1871 obd_types[1] = obd_type2;
1873 if (strcmp(argv[1], "osts") == 0) {
1874 strcpy(obd_types[0], "osc");
1875 } else if (strcmp(argv[1], "mds") == 0) {
1876 strcpy(obd_types[0], "mdc");
1877 } else if (strcmp(argv[1], "servers") == 0) {
1879 strcpy(obd_types[0], "osc");
1880 strcpy(obd_types[1], "mdc");
1882 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
1887 rc = llapi_search_mounts(NULL, 0, mntdir, NULL);
1888 if (rc < 0 || mntdir[0] == '\0') {
1889 fprintf(stderr, "No suitable Lustre mount found\n");
1893 rc = llapi_target_iterate(num_types, obd_types,
1894 mntdir, llapi_ping_target);
1897 fprintf(stderr, "error: %s: %s status failed\n",
1904 static int lfs_join(int argc, char **argv)
1906 fprintf(stderr, "join two lustre files into one.\n"
1907 "obsolete, HEAD does not support it anymore.\n");
1911 #ifdef HAVE_SYS_QUOTA_H
1912 static int lfs_quotacheck(int argc, char **argv)
1914 int c, check_type = 0;
1916 struct if_quotacheck qchk;
1917 struct if_quotactl qctl;
1918 char *obd_type = (char *)qchk.obd_type;
1921 memset(&qchk, 0, sizeof(qchk));
1924 while ((c = getopt(argc, argv, "gu")) != -1) {
1933 fprintf(stderr, "error: %s: option '-%c' "
1934 "unrecognized\n", argv[0], c);
1941 else /* do quotacheck for both user & group quota by default */
1949 rc = llapi_quotacheck(mnt, check_type);
1950 if (rc == -EOPNOTSUPP) {
1951 fprintf(stderr, "error: quotacheck not supported by the quota "
1952 "master.\nPlease note that quotacheck is deprecated as "
1953 "of lustre 2.4.0 since space accounting is always "
1954 "enabled.\nFilesystems not formatted with 2.4 utils or "
1955 "beyond can be upgraded with tunefs.lustre --quota.\n");
1958 fprintf(stderr, "quotacheck failed: %s\n", strerror(-rc));
1962 rc = llapi_poll_quotacheck(mnt, &qchk);
1965 fprintf(stderr, "%s %s ", obd_type,
1966 obd_uuid2str(&qchk.obd_uuid));
1967 fprintf(stderr, "quota check failed: %s\n", strerror(-rc));
1971 memset(&qctl, 0, sizeof(qctl));
1972 qctl.qc_cmd = LUSTRE_Q_QUOTAON;
1973 qctl.qc_type = check_type;
1974 rc = llapi_quotactl(mnt, &qctl);
1975 if (rc && rc != -EALREADY) {
1977 fprintf(stderr, "%s %s ", (char *)qctl.obd_type,
1978 obd_uuid2str(&qctl.obd_uuid));
1979 fprintf(stderr, "%s turn on quota failed: %s\n",
1980 argv[0], strerror(-rc));
1987 static int lfs_quotaon(int argc, char **argv)
1991 struct if_quotactl qctl;
1992 char *obd_type = (char *)qctl.obd_type;
1995 memset(&qctl, 0, sizeof(qctl));
1996 qctl.qc_cmd = LUSTRE_Q_QUOTAON;
1999 while ((c = getopt(argc, argv, "fgu")) != -1) {
2002 qctl.qc_type |= 0x01;
2005 qctl.qc_type |= 0x02;
2008 qctl.qc_cmd = LUSTRE_Q_QUOTAOFF;
2011 fprintf(stderr, "error: %s: option '-%c' "
2012 "unrecognized\n", argv[0], c);
2019 else /* by default, enable quota for both user & group */
2020 qctl.qc_type = 0x02;
2027 rc = llapi_quotactl(mnt, &qctl);
2029 if (rc == -EOPNOTSUPP) {
2030 fprintf(stderr, "error: quotaon not supported by the "
2031 "quota master.\nPlease note that quotaon/off is"
2032 " deprecated as of lustre 2.4.0.\nQuota "
2033 "enforcement should now be enabled on the MGS "
2034 "via:\nmgs# lctl conf_param ${FSNAME}.quota."
2035 "<ost|mdt>=<u|g|ug>\n(ost for block quota, mdt "
2036 "for inode quota, u for user and g for group"
2038 } else if (rc == -EALREADY) {
2040 } else if (rc == -ENOENT) {
2041 fprintf(stderr, "error: cannot find quota database, "
2042 "make sure you have run quotacheck\n");
2045 fprintf(stderr, "%s %s ", obd_type,
2046 obd_uuid2str(&qctl.obd_uuid));
2047 fprintf(stderr, "%s failed: %s\n", argv[0],
2055 static int lfs_quotaoff(int argc, char **argv)
2059 struct if_quotactl qctl;
2060 char *obd_type = (char *)qctl.obd_type;
2063 memset(&qctl, 0, sizeof(qctl));
2064 qctl.qc_cmd = LUSTRE_Q_QUOTAOFF;
2067 while ((c = getopt(argc, argv, "gu")) != -1) {
2070 qctl.qc_type |= 0x01;
2073 qctl.qc_type |= 0x02;
2076 fprintf(stderr, "error: %s: option '-%c' "
2077 "unrecognized\n", argv[0], c);
2084 else /* by default, disable quota for both user & group */
2085 qctl.qc_type = 0x02;
2092 rc = llapi_quotactl(mnt, &qctl);
2094 if (rc == -EOPNOTSUPP) {
2095 fprintf(stderr, "error: quotaoff not supported by the "
2096 "quota master.\nPlease note that quotaon/off is"
2097 " deprecated as of lustre 2.4.0.\nQuota "
2098 "enforcement can be disabled on the MGS via:\n"
2099 "mgs# lctl conf_param ${FSNAME}.quota.<ost|mdt>"
2101 } else if (rc == -EALREADY) {
2105 fprintf(stderr, "%s %s ", obd_type,
2106 obd_uuid2str(&qctl.obd_uuid));
2107 fprintf(stderr, "quotaoff failed: %s\n",
2115 #define ARG2INT(nr, str, msg) \
2118 nr = strtol(str, &endp, 0); \
2120 fprintf(stderr, "error: bad %s: %s\n", msg, str); \
2125 #define ADD_OVERFLOW(a,b) ((a + b) < a) ? (a = ULONG_MAX) : (a = a + b)
2127 /* Convert format time string "XXwXXdXXhXXmXXs" into seconds value
2128 * returns the value or ULONG_MAX on integer overflow or incorrect format
2130 * 1. the order of specifiers is arbitrary (may be: 5w3s or 3s5w)
2131 * 2. specifiers may be encountered multiple times (2s3s is 5 seconds)
2132 * 3. empty integer value is interpreted as 0
2134 static unsigned long str2sec(const char* timestr)
2136 const char spec[] = "smhdw";
2137 const unsigned long mult[] = {1, 60, 60*60, 24*60*60, 7*24*60*60};
2138 unsigned long val = 0;
2141 if (strpbrk(timestr, spec) == NULL) {
2142 /* no specifiers inside the time string,
2143 should treat it as an integer value */
2144 val = strtoul(timestr, &tail, 10);
2145 return *tail ? ULONG_MAX : val;
2148 /* format string is XXwXXdXXhXXmXXs */
2154 v = strtoul(timestr, &tail, 10);
2155 if (v == ULONG_MAX || *tail == '\0')
2156 /* value too large (ULONG_MAX or more)
2157 or missing specifier */
2160 ptr = strchr(spec, *tail);
2162 /* unknown specifier */
2167 /* check if product will overflow the type */
2168 if (!(v < ULONG_MAX / mult[ind]))
2171 ADD_OVERFLOW(val, mult[ind] * v);
2172 if (val == ULONG_MAX)
2184 #define ARG2ULL(nr, str, def_units) \
2186 unsigned long long limit, units = def_units; \
2189 rc = llapi_parse_size(str, &limit, &units, 1); \
2191 fprintf(stderr, "error: bad limit value %s\n", str); \
2197 static inline int has_times_option(int argc, char **argv)
2201 for (i = 1; i < argc; i++)
2202 if (!strcmp(argv[i], "-t"))
2208 int lfs_setquota_times(int argc, char **argv)
2211 struct if_quotactl qctl;
2212 char *mnt, *obd_type = (char *)qctl.obd_type;
2213 struct obd_dqblk *dqb = &qctl.qc_dqblk;
2214 struct obd_dqinfo *dqi = &qctl.qc_dqinfo;
2215 struct option long_opts[] = {
2216 {"block-grace", required_argument, 0, 'b'},
2217 {"group", no_argument, 0, 'g'},
2218 {"inode-grace", required_argument, 0, 'i'},
2219 {"times", no_argument, 0, 't'},
2220 {"user", no_argument, 0, 'u'},
2224 memset(&qctl, 0, sizeof(qctl));
2225 qctl.qc_cmd = LUSTRE_Q_SETINFO;
2226 qctl.qc_type = UGQUOTA;
2229 while ((c = getopt_long(argc, argv, "b:gi:tu", long_opts, NULL)) != -1) {
2233 if (qctl.qc_type != UGQUOTA) {
2234 fprintf(stderr, "error: -u and -g can't be used "
2235 "more than once\n");
2238 qctl.qc_type = (c == 'u') ? USRQUOTA : GRPQUOTA;
2241 if ((dqi->dqi_bgrace = str2sec(optarg)) == ULONG_MAX) {
2242 fprintf(stderr, "error: bad block-grace: %s\n",
2246 dqb->dqb_valid |= QIF_BTIME;
2249 if ((dqi->dqi_igrace = str2sec(optarg)) == ULONG_MAX) {
2250 fprintf(stderr, "error: bad inode-grace: %s\n",
2254 dqb->dqb_valid |= QIF_ITIME;
2256 case 't': /* Yes, of course! */
2258 default: /* getopt prints error message for us when opterr != 0 */
2263 if (qctl.qc_type == UGQUOTA) {
2264 fprintf(stderr, "error: neither -u nor -g specified\n");
2268 if (optind != argc - 1) {
2269 fprintf(stderr, "error: unexpected parameters encountered\n");
2274 rc = llapi_quotactl(mnt, &qctl);
2277 fprintf(stderr, "%s %s ", obd_type,
2278 obd_uuid2str(&qctl.obd_uuid));
2279 fprintf(stderr, "setquota failed: %s\n", strerror(-rc));
2286 #define BSLIMIT (1 << 0)
2287 #define BHLIMIT (1 << 1)
2288 #define ISLIMIT (1 << 2)
2289 #define IHLIMIT (1 << 3)
2291 int lfs_setquota(int argc, char **argv)
2294 struct if_quotactl qctl;
2295 char *mnt, *obd_type = (char *)qctl.obd_type;
2296 struct obd_dqblk *dqb = &qctl.qc_dqblk;
2297 struct option long_opts[] = {
2298 {"block-softlimit", required_argument, 0, 'b'},
2299 {"block-hardlimit", required_argument, 0, 'B'},
2300 {"group", required_argument, 0, 'g'},
2301 {"inode-softlimit", required_argument, 0, 'i'},
2302 {"inode-hardlimit", required_argument, 0, 'I'},
2303 {"user", required_argument, 0, 'u'},
2306 unsigned limit_mask = 0;
2309 if (has_times_option(argc, argv))
2310 return lfs_setquota_times(argc, argv);
2312 memset(&qctl, 0, sizeof(qctl));
2313 qctl.qc_cmd = LUSTRE_Q_SETQUOTA;
2314 qctl.qc_type = UGQUOTA; /* UGQUOTA makes no sense for setquota,
2315 * so it can be used as a marker that qc_type
2316 * isn't reinitialized from command line */
2319 while ((c = getopt_long(argc, argv, "b:B:g:i:I:u:", long_opts, NULL)) != -1) {
2323 if (qctl.qc_type != UGQUOTA) {
2324 fprintf(stderr, "error: -u and -g can't be used"
2325 " more than once\n");
2328 qctl.qc_type = (c == 'u') ? USRQUOTA : GRPQUOTA;
2329 rc = name2id(&qctl.qc_id, optarg,
2330 (qctl.qc_type == USRQUOTA) ? USER : GROUP);
2332 qctl.qc_id = strtoul(optarg, &endptr, 10);
2333 if (*endptr != '\0') {
2334 fprintf(stderr, "error: can't find id "
2335 "for name %s\n", optarg);
2341 ARG2ULL(dqb->dqb_bsoftlimit, optarg, 1024);
2342 dqb->dqb_bsoftlimit >>= 10;
2343 limit_mask |= BSLIMIT;
2344 if (dqb->dqb_bsoftlimit &&
2345 dqb->dqb_bsoftlimit <= 1024) /* <= 1M? */
2346 fprintf(stderr, "warning: block softlimit is "
2347 "smaller than the miminal qunit size, "
2348 "please see the help of setquota or "
2349 "Lustre manual for details.\n");
2352 ARG2ULL(dqb->dqb_bhardlimit, optarg, 1024);
2353 dqb->dqb_bhardlimit >>= 10;
2354 limit_mask |= BHLIMIT;
2355 if (dqb->dqb_bhardlimit &&
2356 dqb->dqb_bhardlimit <= 1024) /* <= 1M? */
2357 fprintf(stderr, "warning: block hardlimit is "
2358 "smaller than the miminal qunit size, "
2359 "please see the help of setquota or "
2360 "Lustre manual for details.\n");
2363 ARG2ULL(dqb->dqb_isoftlimit, optarg, 1);
2364 limit_mask |= ISLIMIT;
2365 if (dqb->dqb_isoftlimit &&
2366 dqb->dqb_isoftlimit <= 1024) /* <= 1K inodes? */
2367 fprintf(stderr, "warning: inode softlimit is "
2368 "smaller than the miminal qunit size, "
2369 "please see the help of setquota or "
2370 "Lustre manual for details.\n");
2373 ARG2ULL(dqb->dqb_ihardlimit, optarg, 1);
2374 limit_mask |= IHLIMIT;
2375 if (dqb->dqb_ihardlimit &&
2376 dqb->dqb_ihardlimit <= 1024) /* <= 1K inodes? */
2377 fprintf(stderr, "warning: inode hardlimit is "
2378 "smaller than the miminal qunit size, "
2379 "please see the help of setquota or "
2380 "Lustre manual for details.\n");
2382 default: /* getopt prints error message for us when opterr != 0 */
2387 if (qctl.qc_type == UGQUOTA) {
2388 fprintf(stderr, "error: neither -u nor -g was specified\n");
2392 if (limit_mask == 0) {
2393 fprintf(stderr, "error: at least one limit must be specified\n");
2397 if (optind != argc - 1) {
2398 fprintf(stderr, "error: unexpected parameters encountered\n");
2404 if ((!(limit_mask & BHLIMIT) ^ !(limit_mask & BSLIMIT)) ||
2405 (!(limit_mask & IHLIMIT) ^ !(limit_mask & ISLIMIT))) {
2406 /* sigh, we can't just set blimits/ilimits */
2407 struct if_quotactl tmp_qctl = {.qc_cmd = LUSTRE_Q_GETQUOTA,
2408 .qc_type = qctl.qc_type,
2409 .qc_id = qctl.qc_id};
2411 rc = llapi_quotactl(mnt, &tmp_qctl);
2413 fprintf(stderr, "error: setquota failed while retrieving"
2414 " current quota settings (%s)\n",
2419 if (!(limit_mask & BHLIMIT))
2420 dqb->dqb_bhardlimit = tmp_qctl.qc_dqblk.dqb_bhardlimit;
2421 if (!(limit_mask & BSLIMIT))
2422 dqb->dqb_bsoftlimit = tmp_qctl.qc_dqblk.dqb_bsoftlimit;
2423 if (!(limit_mask & IHLIMIT))
2424 dqb->dqb_ihardlimit = tmp_qctl.qc_dqblk.dqb_ihardlimit;
2425 if (!(limit_mask & ISLIMIT))
2426 dqb->dqb_isoftlimit = tmp_qctl.qc_dqblk.dqb_isoftlimit;
2428 /* Keep grace times if we have got no softlimit arguments */
2429 if ((limit_mask & BHLIMIT) && !(limit_mask & BSLIMIT)) {
2430 dqb->dqb_valid |= QIF_BTIME;
2431 dqb->dqb_btime = tmp_qctl.qc_dqblk.dqb_btime;
2434 if ((limit_mask & IHLIMIT) && !(limit_mask & ISLIMIT)) {
2435 dqb->dqb_valid |= QIF_ITIME;
2436 dqb->dqb_itime = tmp_qctl.qc_dqblk.dqb_itime;
2440 dqb->dqb_valid |= (limit_mask & (BHLIMIT | BSLIMIT)) ? QIF_BLIMITS : 0;
2441 dqb->dqb_valid |= (limit_mask & (IHLIMIT | ISLIMIT)) ? QIF_ILIMITS : 0;
2443 rc = llapi_quotactl(mnt, &qctl);
2446 fprintf(stderr, "%s %s ", obd_type,
2447 obd_uuid2str(&qctl.obd_uuid));
2448 fprintf(stderr, "setquota failed: %s\n", strerror(-rc));
2455 static inline char *type2name(int check_type)
2457 if (check_type == USRQUOTA)
2459 else if (check_type == GRPQUOTA)
2465 /* Converts seconds value into format string
2466 * result is returned in buf
2468 * 1. result is in descenting order: 1w2d3h4m5s
2469 * 2. zero fields are not filled (except for p. 3): 5d1s
2470 * 3. zero seconds value is presented as "0s"
2472 static char * __sec2str(time_t seconds, char *buf)
2474 const char spec[] = "smhdw";
2475 const unsigned long mult[] = {1, 60, 60*60, 24*60*60, 7*24*60*60};
2480 for (i = sizeof(mult) / sizeof(mult[0]) - 1 ; i >= 0; i--) {
2481 c = seconds / mult[i];
2483 if (c > 0 || (i == 0 && buf == tail))
2484 tail += snprintf(tail, 40-(tail-buf), "%lu%c", c, spec[i]);
2492 static void sec2str(time_t seconds, char *buf, int rc)
2499 tail = __sec2str(seconds, tail);
2501 if (rc && tail - buf < 39) {
2507 static void diff2str(time_t seconds, char *buf, time_t now)
2513 if (seconds <= now) {
2514 strcpy(buf, "none");
2517 __sec2str(seconds - now, buf);
2520 static void print_quota_title(char *name, struct if_quotactl *qctl)
2522 printf("Disk quotas for %s %s (%cid %u):\n",
2523 type2name(qctl->qc_type), name,
2524 *type2name(qctl->qc_type), qctl->qc_id);
2525 printf("%15s%8s %7s%8s%8s%8s %7s%8s%8s\n",
2527 "kbytes", "quota", "limit", "grace",
2528 "files", "quota", "limit", "grace");
2531 static void print_quota(char *mnt, struct if_quotactl *qctl, int type, int rc)
2537 if (qctl->qc_cmd == LUSTRE_Q_GETQUOTA || qctl->qc_cmd == Q_GETOQUOTA) {
2538 int bover = 0, iover = 0;
2539 struct obd_dqblk *dqb = &qctl->qc_dqblk;
2541 if (dqb->dqb_bhardlimit &&
2542 toqb(dqb->dqb_curspace) >= dqb->dqb_bhardlimit) {
2544 } else if (dqb->dqb_bsoftlimit && dqb->dqb_btime) {
2545 if (dqb->dqb_btime > now) {
2552 if (dqb->dqb_ihardlimit &&
2553 dqb->dqb_curinodes >= dqb->dqb_ihardlimit) {
2555 } else if (dqb->dqb_isoftlimit && dqb->dqb_itime) {
2556 if (dqb->dqb_itime > now) {
2563 #if 0 /* XXX: always print quotas even when no usages */
2564 if (dqb->dqb_curspace || dqb->dqb_curinodes)
2570 if (strlen(mnt) > 15)
2571 printf("%s\n%15s", mnt, "");
2573 printf("%15s", mnt);
2576 diff2str(dqb->dqb_btime, timebuf, now);
2577 if (rc == -EREMOTEIO)
2578 sprintf(numbuf[0], LPU64"*",
2579 toqb(dqb->dqb_curspace));
2582 (dqb->dqb_valid & QIF_SPACE) ?
2583 LPU64 : "["LPU64"]",
2584 toqb(dqb->dqb_curspace));
2585 if (type == QC_GENERAL)
2586 sprintf(numbuf[1], (dqb->dqb_valid & QIF_BLIMITS)
2587 ? LPU64 : "["LPU64"]",
2588 dqb->dqb_bsoftlimit);
2590 sprintf(numbuf[1], "%s", "-");
2591 sprintf(numbuf[2], (dqb->dqb_valid & QIF_BLIMITS)
2592 ? LPU64 : "["LPU64"]", dqb->dqb_bhardlimit);
2593 printf(" %7s%c %6s %7s %7s",
2594 numbuf[0], bover ? '*' : ' ', numbuf[1],
2595 numbuf[2], bover > 1 ? timebuf : "-");
2598 diff2str(dqb->dqb_itime, timebuf, now);
2600 sprintf(numbuf[0], (dqb->dqb_valid & QIF_INODES) ?
2601 LPU64 : "["LPU64"]", dqb->dqb_curinodes);
2602 if (type == QC_GENERAL)
2603 sprintf(numbuf[1], (dqb->dqb_valid & QIF_ILIMITS)
2604 ? LPU64 : "["LPU64"]",
2605 dqb->dqb_isoftlimit);
2607 sprintf(numbuf[1], "%s", "-");
2608 sprintf(numbuf[2], (dqb->dqb_valid & QIF_ILIMITS) ?
2609 LPU64 : "["LPU64"]", dqb->dqb_ihardlimit);
2610 if (type != QC_OSTIDX)
2611 printf(" %7s%c %6s %7s %7s",
2612 numbuf[0], iover ? '*' : ' ', numbuf[1],
2613 numbuf[2], iover > 1 ? timebuf : "-");
2615 printf(" %7s %7s %7s %7s", "-", "-", "-", "-");
2618 } else if (qctl->qc_cmd == LUSTRE_Q_GETINFO ||
2619 qctl->qc_cmd == Q_GETOINFO) {
2623 sec2str(qctl->qc_dqinfo.dqi_bgrace, bgtimebuf, rc);
2624 sec2str(qctl->qc_dqinfo.dqi_igrace, igtimebuf, rc);
2625 printf("Block grace time: %s; Inode grace time: %s\n",
2626 bgtimebuf, igtimebuf);
2630 static int print_obd_quota(char *mnt, struct if_quotactl *qctl, int is_mdt)
2632 int rc = 0, rc1 = 0, count = 0;
2633 __u32 valid = qctl->qc_valid;
2635 rc = llapi_get_obd_count(mnt, &count, is_mdt);
2637 fprintf(stderr, "can not get %s count: %s\n",
2638 is_mdt ? "mdt": "ost", strerror(-rc));
2642 for (qctl->qc_idx = 0; qctl->qc_idx < count; qctl->qc_idx++) {
2643 qctl->qc_valid = is_mdt ? QC_MDTIDX : QC_OSTIDX;
2644 rc = llapi_quotactl(mnt, qctl);
2646 /* It is remote client case. */
2647 if (-rc == EOPNOTSUPP) {
2654 fprintf(stderr, "quotactl %s%d failed.\n",
2655 is_mdt ? "mdt": "ost", qctl->qc_idx);
2659 print_quota(obd_uuid2str(&qctl->obd_uuid), qctl, qctl->qc_valid, 0);
2663 qctl->qc_valid = valid;
2667 static int lfs_quota(int argc, char **argv)
2670 char *mnt, *name = NULL;
2671 struct if_quotactl qctl = { .qc_cmd = LUSTRE_Q_GETQUOTA,
2672 .qc_type = UGQUOTA };
2673 char *obd_type = (char *)qctl.obd_type;
2674 char *obd_uuid = (char *)qctl.obd_uuid.uuid;
2675 int rc, rc1 = 0, rc2 = 0, rc3 = 0,
2676 verbose = 0, pass = 0, quiet = 0, inacc;
2678 __u32 valid = QC_GENERAL, idx = 0;
2681 while ((c = getopt(argc, argv, "gi:I:o:qtuv")) != -1) {
2684 if (qctl.qc_type != UGQUOTA) {
2685 fprintf(stderr, "error: use either -u or -g\n");
2688 qctl.qc_type = USRQUOTA;
2691 if (qctl.qc_type != UGQUOTA) {
2692 fprintf(stderr, "error: use either -u or -g\n");
2695 qctl.qc_type = GRPQUOTA;
2698 qctl.qc_cmd = LUSTRE_Q_GETINFO;
2701 valid = qctl.qc_valid = QC_UUID;
2702 strncpy(obd_uuid, optarg, sizeof(qctl.obd_uuid));
2705 valid = qctl.qc_valid = QC_MDTIDX;
2706 idx = qctl.qc_idx = atoi(optarg);
2709 valid = qctl.qc_valid = QC_OSTIDX;
2710 idx = qctl.qc_idx = atoi(optarg);
2719 fprintf(stderr, "error: %s: option '-%c' "
2720 "unrecognized\n", argv[0], c);
2725 /* current uid/gid info for "lfs quota /path/to/lustre/mount" */
2726 if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA && qctl.qc_type == UGQUOTA &&
2727 optind == argc - 1) {
2729 memset(&qctl, 0, sizeof(qctl)); /* spoiled by print_*_quota */
2730 qctl.qc_cmd = LUSTRE_Q_GETQUOTA;
2731 qctl.qc_valid = valid;
2734 qctl.qc_type = USRQUOTA;
2735 qctl.qc_id = geteuid();
2737 qctl.qc_type = GRPQUOTA;
2738 qctl.qc_id = getegid();
2740 rc = id2name(&name, qctl.qc_id,
2741 (qctl.qc_type == USRQUOTA) ? USER : GROUP);
2744 /* lfs quota -u username /path/to/lustre/mount */
2745 } else if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) {
2746 /* options should be followed by u/g-name and mntpoint */
2747 if (optind + 2 != argc || qctl.qc_type == UGQUOTA) {
2748 fprintf(stderr, "error: missing quota argument(s)\n");
2752 name = argv[optind++];
2753 rc = name2id(&qctl.qc_id, name,
2754 (qctl.qc_type == USRQUOTA) ? USER : GROUP);
2756 qctl.qc_id = strtoul(name, &endptr, 10);
2757 if (*endptr != '\0') {
2758 fprintf(stderr, "error: can't find id for name "
2763 } else if (optind + 1 != argc || qctl.qc_type == UGQUOTA) {
2764 fprintf(stderr, "error: missing quota info argument(s)\n");
2770 rc1 = llapi_quotactl(mnt, &qctl);
2774 fprintf(stderr, "%s quotas are not enabled.\n",
2775 qctl.qc_type == USRQUOTA ? "user" : "group");
2778 fprintf(stderr, "Permission denied.\n");
2780 /* We already got a "No such file..." message. */
2783 fprintf(stderr, "Unexpected quotactl error: %s\n",
2788 if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA && !quiet)
2789 print_quota_title(name, &qctl);
2791 if (rc1 && *obd_type)
2792 fprintf(stderr, "%s %s ", obd_type, obd_uuid);
2794 if (qctl.qc_valid != QC_GENERAL)
2797 inacc = (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) &&
2798 ((qctl.qc_dqblk.dqb_valid&(QIF_LIMITS|QIF_USAGE))!=(QIF_LIMITS|QIF_USAGE));
2800 print_quota(mnt, &qctl, QC_GENERAL, rc1);
2802 if (qctl.qc_valid == QC_GENERAL && qctl.qc_cmd != LUSTRE_Q_GETINFO && verbose) {
2803 rc2 = print_obd_quota(mnt, &qctl, 1);
2804 rc3 = print_obd_quota(mnt, &qctl, 0);
2807 if (rc1 || rc2 || rc3 || inacc)
2808 printf("Some errors happened when getting quota info. "
2809 "Some devices may be not working or deactivated. "
2810 "The data in \"[]\" is inaccurate.\n");
2818 #endif /* HAVE_SYS_QUOTA_H! */
2820 static int flushctx_ioctl(char *mp)
2824 fd = open(mp, O_RDONLY);
2826 fprintf(stderr, "flushctx: error open %s: %s\n",
2827 mp, strerror(errno));
2831 rc = ioctl(fd, LL_IOC_FLUSHCTX);
2833 fprintf(stderr, "flushctx: error ioctl %s: %s\n",
2834 mp, strerror(errno));
2840 static int lfs_flushctx(int argc, char **argv)
2842 int kdestroy = 0, c;
2844 char procline[PATH_MAX], *line;
2848 while ((c = getopt(argc, argv, "k")) != -1) {
2854 fprintf(stderr, "error: %s: option '-%c' "
2855 "unrecognized\n", argv[0], c);
2862 if ((rc = system("kdestroy > /dev/null")) != 0) {
2863 rc = WEXITSTATUS(rc);
2864 fprintf(stderr, "error destroying tickets: %d, continuing\n", rc);
2868 if (optind >= argc) {
2869 /* flush for all mounted lustre fs. */
2870 proc = fopen("/proc/mounts", "r");
2872 fprintf(stderr, "error: %s: can't open /proc/mounts\n",
2877 while ((line = fgets(procline, PATH_MAX, proc)) != NULL) {
2882 if (sscanf(line, "%s %s %s", dev, mp, fs) != 3) {
2883 fprintf(stderr, "%s: unexpected format in "
2890 if (strcmp(fs, "lustre") != 0)
2892 /* we use '@' to determine it's a client. are there
2893 * any other better way?
2895 if (strchr(dev, '@') == NULL)
2898 if (flushctx_ioctl(mp))
2902 /* flush fs as specified */
2903 while (optind < argc) {
2904 if (flushctx_ioctl(argv[optind++]))
2915 static int lfs_lsetfacl(int argc, char **argv)
2918 return(llapi_lsetfacl(argc, argv));
2921 static int lfs_lgetfacl(int argc, char **argv)
2924 return(llapi_lgetfacl(argc, argv));
2927 static int lfs_rsetfacl(int argc, char **argv)
2930 return(llapi_rsetfacl(argc, argv));
2933 static int lfs_rgetfacl(int argc, char **argv)
2936 return(llapi_rgetfacl(argc, argv));
2939 static int lfs_cp(int argc, char **argv)
2941 return(llapi_cp(argc, argv));
2944 static int lfs_ls(int argc, char **argv)
2946 return(llapi_ls(argc, argv));
2949 static int lfs_changelog(int argc, char **argv)
2951 void *changelog_priv;
2952 struct changelog_ext_rec *rec;
2953 long long startrec = 0, endrec = 0;
2955 struct option long_opts[] = {
2956 {"follow", no_argument, 0, 'f'},
2959 char short_opts[] = "f";
2963 while ((rc = getopt_long(argc, argv, short_opts,
2964 long_opts, NULL)) != -1) {
2972 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
2973 argv[0], argv[optind - 1]);
2980 mdd = argv[optind++];
2982 startrec = strtoll(argv[optind++], NULL, 10);
2984 endrec = strtoll(argv[optind++], NULL, 10);
2986 rc = llapi_changelog_start(&changelog_priv,
2987 CHANGELOG_FLAG_BLOCK |
2988 (follow ? CHANGELOG_FLAG_FOLLOW : 0),
2991 fprintf(stderr, "Can't start changelog: %s\n",
2992 strerror(errno = -rc));
2996 while ((rc = llapi_changelog_recv(changelog_priv, &rec)) == 0) {
3000 if (endrec && rec->cr_index > endrec) {
3001 llapi_changelog_free(&rec);
3004 if (rec->cr_index < startrec) {
3005 llapi_changelog_free(&rec);
3009 secs = rec->cr_time >> 30;
3010 gmtime_r(&secs, &ts);
3011 printf(LPU64" %02d%-5s %02d:%02d:%02d.%06d %04d.%02d.%02d "
3012 "0x%x t="DFID, rec->cr_index, rec->cr_type,
3013 changelog_type2str(rec->cr_type),
3014 ts.tm_hour, ts.tm_min, ts.tm_sec,
3015 (int)(rec->cr_time & ((1<<30) - 1)),
3016 ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday,
3017 rec->cr_flags & CLF_FLAGMASK, PFID(&rec->cr_tfid));
3018 if (rec->cr_namelen)
3019 /* namespace rec includes parent and filename */
3020 printf(" p="DFID" %.*s", PFID(&rec->cr_pfid),
3021 rec->cr_namelen, rec->cr_name);
3022 if (fid_is_sane(&rec->cr_sfid))
3023 printf(" s="DFID" sp="DFID" %.*s",
3024 PFID(&rec->cr_sfid), PFID(&rec->cr_spfid),
3025 changelog_rec_snamelen(rec),
3026 changelog_rec_sname(rec));
3029 llapi_changelog_free(&rec);
3032 llapi_changelog_fini(&changelog_priv);
3035 fprintf(stderr, "Changelog: %s\n", strerror(errno = -rc));
3037 return (rc == 1 ? 0 : rc);
3040 static int lfs_changelog_clear(int argc, char **argv)
3048 endrec = strtoll(argv[3], NULL, 10);
3050 rc = llapi_changelog_clear(argv[1], argv[2], endrec);
3052 fprintf(stderr, "%s error: %s\n", argv[0],
3053 strerror(errno = -rc));
3057 static int lfs_fid2path(int argc, char **argv)
3059 struct option long_opts[] = {
3060 {"cur", no_argument, 0, 'c'},
3061 {"link", required_argument, 0, 'l'},
3062 {"rec", required_argument, 0, 'r'},
3065 char short_opts[] = "cl:r:";
3066 char *device, *fid, *path;
3067 long long recno = -1;
3075 while ((rc = getopt_long(argc, argv, short_opts,
3076 long_opts, NULL)) != -1) {
3082 linkno = strtol(optarg, NULL, 10);
3085 recno = strtoll(optarg, NULL, 10);
3090 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
3091 argv[0], argv[optind - 1]);
3099 device = argv[optind++];
3100 path = calloc(1, PATH_MAX);
3103 while (optind < argc) {
3104 fid = argv[optind++];
3106 lnktmp = (linkno >= 0) ? linkno : 0;
3108 int oldtmp = lnktmp;
3109 long long rectmp = recno;
3111 rc2 = llapi_fid2path(device, fid, path, PATH_MAX,
3114 fprintf(stderr, "%s: error on FID %s: %s\n",
3115 argv[0], fid, strerror(errno = -rc2));
3122 fprintf(stdout, "%lld ", rectmp);
3123 if (device[0] == '/') {
3124 fprintf(stdout, "%s", device);
3125 if (device[strlen(device) - 1] != '/')
3126 fprintf(stdout, "/");
3127 } else if (path[0] == '\0') {
3128 fprintf(stdout, "/");
3130 fprintf(stdout, "%s\n", path);
3133 /* specified linkno */
3135 if (oldtmp == lnktmp)
3145 static int lfs_path2fid(int argc, char **argv)
3148 const char *sep = "";
3158 while (*path != NULL) {
3159 int err = llapi_path2fid(*path, &fid);
3162 fprintf(stderr, "%s: can't get fid for %s: %s\n",
3163 argv[0], *path, strerror(-err));
3170 printf("%s%s"DFID"\n", *sep != '\0' ? *path : "", sep,
3179 static int lfs_data_version(int argc, char **argv)
3192 while ((c = getopt(argc, argv, "n")) != -1) {
3195 nolock = LL_DV_NOFLUSH;
3204 path = argv[optind];
3205 fd = open(path, O_RDONLY);
3207 fprintf(stderr, "can't open %s: %s\n", path,
3212 rc = llapi_get_data_version(fd, &data_version, nolock);
3214 fprintf(stderr, "can't get version for %s: %s\n", path,
3215 strerror(errno = -rc));
3217 printf(LPU64 "\n", data_version);
3224 static int lfs_hsm_state(int argc, char **argv)
3229 struct hsm_user_state hus;
3237 rc = llapi_hsm_state_get(path, &hus);
3239 fprintf(stderr, "can't get hsm state for %s: %s\n",
3240 path, strerror(errno = -rc));
3244 /* Display path name and status flags */
3245 printf("%s: (0x%08x)", path, hus.hus_states);
3247 if (hus.hus_states & HS_RELEASED)
3248 printf(" released");
3249 if (hus.hus_states & HS_EXISTS)
3251 if (hus.hus_states & HS_DIRTY)
3253 if (hus.hus_states & HS_ARCHIVED)
3254 printf(" archived");
3255 /* Display user-settable flags */
3256 if (hus.hus_states & HS_NORELEASE)
3257 printf(" never_release");
3258 if (hus.hus_states & HS_NOARCHIVE)
3259 printf(" never_archive");
3260 if (hus.hus_states & HS_LOST)
3261 printf(" lost_from_hsm");
3263 if (hus.hus_archive_id != 0)
3264 printf(", archive_id:%d", hus.hus_archive_id);
3267 } while (++i < argc);
3272 #define LFS_HSM_SET 0
3273 #define LFS_HSM_CLEAR 1
3276 * Generic function to set or clear HSM flags.
3277 * Used by hsm_set and hsm_clear.
3279 * @mode if LFS_HSM_SET, set the flags, if LFS_HSM_CLEAR, clear the flags.
3281 static int lfs_hsm_change_flags(int argc, char **argv, int mode)
3283 struct option long_opts[] = {
3284 {"lost", 0, 0, 'l'},
3285 {"norelease", 0, 0, 'r'},
3286 {"noarchive", 0, 0, 'a'},
3287 {"archived", 0, 0, 'A'},
3288 {"dirty", 0, 0, 'd'},
3289 {"exists", 0, 0, 'e'},
3292 char short_opts[] = "lraAde";
3301 while ((c = getopt_long(argc, argv, short_opts,
3302 long_opts, NULL)) != -1) {
3308 mask |= HS_NOARCHIVE;
3311 mask |= HS_ARCHIVED;
3314 mask |= HS_NORELEASE;
3325 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
3326 argv[0], argv[optind - 1]);
3331 /* User should have specified a flag */
3335 while (optind < argc) {
3337 path = argv[optind];
3339 /* If mode == 0, this means we apply the mask. */
3340 if (mode == LFS_HSM_SET)
3341 rc = llapi_hsm_state_set(path, mask, 0, 0);
3343 rc = llapi_hsm_state_set(path, 0, mask, 0);
3346 fprintf(stderr, "Can't change hsm flags for %s: %s\n",
3347 path, strerror(errno = -rc));
3356 static int lfs_hsm_action(int argc, char **argv)
3361 struct hsm_current_action hca;
3362 struct hsm_extent he;
3363 enum hsm_user_action hua;
3364 enum hsm_progress_states hps;
3372 rc = llapi_hsm_current_action(path, &hca);
3374 fprintf(stderr, "can't get hsm action for %s: %s\n",
3375 path, strerror(errno = -rc));
3378 he = hca.hca_location;
3379 hua = hca.hca_action;
3380 hps = hca.hca_state;
3382 printf("%s: %s", path, hsm_user_action2name(hua));
3384 /* Skip file without action */
3385 if (hca.hca_action == HUA_NONE) {
3390 printf(" %s ", hsm_progress_state2name(hps));
3392 if ((hps == HPS_RUNNING) &&
3393 (hua == HUA_ARCHIVE || hua == HUA_RESTORE))
3394 printf("("LPX64 " bytes moved)\n", he.length);
3395 else if ((he.offset + he.length) == OBD_OBJECT_EOF)
3396 printf("(from "LPX64 " to EOF)\n", he.offset);
3398 printf("(from "LPX64 " to "LPX64")\n",
3399 he.offset, he.offset + he.length);
3401 } while (++i < argc);
3406 static int lfs_hsm_set(int argc, char **argv)
3408 return lfs_hsm_change_flags(argc, argv, LFS_HSM_SET);
3411 static int lfs_hsm_clear(int argc, char **argv)
3413 return lfs_hsm_change_flags(argc, argv, LFS_HSM_CLEAR);
3417 * Check file state and return its fid, to be used by lfs_hsm_request().
3419 * \param[in] file Path to file to check
3420 * \param[in,out] fid Pointer to allocated lu_fid struct.
3421 * \param[in,out] last_dev Pointer to last device id used.
3423 * \return 0 on success.
3425 static int lfs_hsm_prepare_file(char *file, struct lu_fid *fid,
3431 rc = lstat(file, &st);
3433 fprintf(stderr, "Cannot stat %s: %s\n", file, strerror(errno));
3436 /* A request should be ... */
3437 if (*last_dev != st.st_dev && *last_dev != 0) {
3438 fprintf(stderr, "All files should be "
3439 "on the same filesystem: %s\n", file);
3442 *last_dev = st.st_dev;
3444 rc = llapi_path2fid(file, fid);
3446 fprintf(stderr, "Cannot read FID of %s: %s\n",
3447 file, strerror(-rc));
3453 static int lfs_hsm_request(int argc, char **argv, int action)
3455 struct option long_opts[] = {
3456 {"filelist", 1, 0, 'l'},
3457 {"data", 1, 0, 'D'},
3458 {"archive", 1, 0, 'a'},
3462 char short_opts[] = "l:D:a:";
3463 struct hsm_user_request *hur, *oldhur;
3468 char *filelist = NULL;
3469 char fullpath[PATH_MAX];
3470 char *opaque = NULL;
3474 int nbfile_alloc = 0;
3475 char some_file[PATH_MAX+1] = "";
3482 while ((c = getopt_long(argc, argv, short_opts,
3483 long_opts, NULL)) != -1) {
3492 if (action != HUA_ARCHIVE) {
3494 "error: -a is supported only "
3495 "when archiving\n");
3498 archive_id = atoi(optarg);
3503 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
3504 argv[0], argv[optind - 1]);
3509 /* All remaining args are files, so we have at least nbfile */
3510 nbfile = argc - optind;
3512 if ((nbfile == 0) && (filelist == NULL))
3516 opaque_len = strlen(opaque);
3518 /* Alloc the request structure with enough place to store all files
3519 * from command line. */
3520 hur = llapi_hsm_user_request_alloc(nbfile, opaque_len);
3522 fprintf(stderr, "Cannot create the request: %s\n",
3526 nbfile_alloc = nbfile;
3528 hur->hur_request.hr_action = action;
3529 hur->hur_request.hr_archive_id = archive_id;
3530 hur->hur_request.hr_flags = 0;
3532 /* All remaining args are files, add them */
3534 strcpy(some_file, argv[optind]);
3536 for (i = 0; i < nbfile; i++) {
3537 hur->hur_user_item[i].hui_extent.length = -1;
3538 rc = lfs_hsm_prepare_file(argv[optind + i],
3539 &hur->hur_user_item[i].hui_fid,
3541 hur->hur_request.hr_itemcount++;
3546 /* from here stop using nb_file, use hur->hur_request.hr_itemcount */
3548 /* If a filelist was specified, read the filelist from it. */
3549 if (filelist != NULL) {
3550 fp = fopen(filelist, "r");
3552 fprintf(stderr, "Cannot read the file list %s: %s\n",
3553 filelist, strerror(errno));
3558 while ((rc = getline(&line, &len, fp)) != -1) {
3559 struct hsm_user_item *hui;
3561 /* If allocated buffer was too small, gets something
3563 if (nbfile_alloc <= hur->hur_request.hr_itemcount) {
3564 nbfile_alloc = nbfile_alloc * 2 + 1;
3566 hur = llapi_hsm_user_request_alloc(nbfile_alloc,
3569 fprintf(stderr, "Cannot allocate "
3570 "the request: %s\n",
3576 memcpy(hur, oldhur, hur_len(oldhur));
3581 if (line[strlen(line) - 1] == '\n')
3582 line[strlen(line) - 1] = '\0';
3585 &hur->hur_user_item[hur->hur_request.hr_itemcount];
3586 hui->hui_extent.length = -1;
3587 rc = lfs_hsm_prepare_file(line, &hui->hui_fid,
3589 hur->hur_request.hr_itemcount++;
3593 if ((some_file[0] == '\0') &&
3594 (strlen(line) < sizeof(some_file)))
3595 strcpy(some_file, line);
3603 /* If a --data was used, add it to the request */
3604 hur->hur_request.hr_data_len = opaque_len;
3606 memcpy(hur_data(hur), opaque, opaque_len);
3608 /* Send the HSM request */
3609 if (realpath(some_file, fullpath) == NULL) {
3610 fprintf(stderr, "Could not find path '%s': %s\n",
3611 some_file, strerror(errno));
3613 rc = llapi_hsm_request(fullpath, hur);
3615 fprintf(stderr, "Cannot send HSM request (use of %s): %s\n",
3616 some_file, strerror(-rc));
3625 static int lfs_hsm_archive(int argc, char **argv)
3627 return lfs_hsm_request(argc, argv, HUA_ARCHIVE);
3630 static int lfs_hsm_restore(int argc, char **argv)
3632 return lfs_hsm_request(argc, argv, HUA_RESTORE);
3635 static int lfs_hsm_release(int argc, char **argv)
3637 return lfs_hsm_request(argc, argv, HUA_RELEASE);
3640 static int lfs_hsm_remove(int argc, char **argv)
3642 return lfs_hsm_request(argc, argv, HUA_REMOVE);
3645 static int lfs_hsm_cancel(int argc, char **argv)
3647 return lfs_hsm_request(argc, argv, HUA_CANCEL);
3650 static int lfs_swap_layouts(int argc, char **argv)
3655 return llapi_swap_layouts(argv[1], argv[2], 0, 0,
3656 SWAP_LAYOUTS_KEEP_MTIME |
3657 SWAP_LAYOUTS_KEEP_ATIME);
3660 int main(int argc, char **argv)
3666 ptl_initialize(argc, argv);
3667 if (obd_initialize(argc, argv) < 0)
3670 Parser_init("lfs > ", cmdlist);
3673 rc = Parser_execarg(argc - 1, argv + 1, cmdlist);
3675 rc = Parser_commands();
3678 obd_finalize(argc, argv);
3679 return rc < 0 ? -rc : rc;