static int lfs_cp(int argc, char **argv);
static int lfs_ls(int argc, char **argv);
static int lfs_poollist(int argc, char **argv);
+static int lfs_path2fid(int argc, char **argv);
/* all avaialable commands */
command_t cmdlist[] = {
{"ls", lfs_ls, 0,
"Remote user list directory contents.\n"
"usage: ls [OPTION]... [FILE]..."},
+ {"path2fid", lfs_path2fid, 0, "Display the fid for a given path.\n"
+ "usage: path2fid <path>"},
{"help", Parser_help, 0, "help"},
{"exit", Parser_quit, 0, "quit"},
{"quit", Parser_quit, 0, "quit"},
{ 0, 0, 0, NULL }
};
+static int isnumber(const char *str)
+{
+ const char *ptr;
+
+ if (str[0] != '-' && !isdigit(str[0]))
+ return 0;
+
+ for (ptr = str + 1; *ptr != '\0'; ptr++) {
+ if (!isdigit(*ptr))
+ return 0;
+ }
+
+ return 1;
+}
+
/* functions */
static int lfs_setstripe(int argc, char **argv)
{
st_size = 0;
st_offset = -1;
st_count = 0;
- if (argc == 3 && strcmp(argv[1], "-d") == 0) {
- /* for compatibility with the existing positional parameter
- * usage */
- fname = argv[2];
- optind = 2;
- } else if (argc == 5 &&
- (argv[2][0] != '-' || isdigit(argv[2][1])) &&
- (argv[3][0] != '-' || isdigit(argv[3][1])) &&
- (argv[4][0] != '-' || isdigit(argv[4][1])) ) {
+
+#if LUSTRE_VERSION < OBD_OCD_VERSION(2,1,0,0)
+ if (argc == 5 && argv[1][0] != '-' &&
+ isnumber(argv[2]) && isnumber(argv[3]) && isnumber(argv[4])) {
+ fprintf(stderr, "warning: deprecated usage of setstripe "
+ "positional parameters. Use -c, -i, -s instead.\n");
/* for compatibility with the existing positional parameter
* usage */
fname = argv[1];
stripe_off_arg = argv[3];
stripe_count_arg = argv[4];
optind = 4;
- } else {
+ } else
+#else
+#warning "remove obsolete positional parameter code"
+#endif
+ {
optind = 0;
while ((c = getopt_long(argc, argv, "c:di:o:s:p:",
long_opts, NULL)) >= 0) {
return CMD_HELP;
}
}
- if (optind < argc)
- fname = argv[optind];
- else
- return CMD_HELP;
+ fname = argv[optind];
if (delete &&
(stripe_size_arg != NULL || stripe_off_arg != NULL ||
return CMD_HELP;
}
}
- if (optind != argc - 1) {
- fprintf(stderr, "error: %s: only 1 filename|dirname can be "
- "specified: '%s'\n",
- argv[0], argv[argc - 1]);
+
+ if (optind == argc) {
+ fprintf(stderr, "error: %s: missing filename|dirname\n",
+ argv[0]);
return CMD_HELP;
}
if (stripe_size_arg != NULL) {
result = parse_size(stripe_size_arg, &st_size, &size_units);
if (result) {
- fprintf(stderr,"error: bad size '%s'\n",
- stripe_size_arg);
+ fprintf(stderr, "error: %s: bad size '%s'\n",
+ argv[0], stripe_size_arg);
return result;
}
}
}
}
- if (pool_name_arg == NULL)
- result = llapi_file_create(fname, st_size, st_offset, st_count, 0);
- else
+ do {
result = llapi_file_create_pool(fname, st_size, st_offset,
st_count, 0, pool_name_arg);
-
- if (result)
- fprintf(stderr, "error: %s: create stripe file failed\n",
- argv[0]);
+ if (result) {
+ fprintf(stderr,"error: %s: create stripe file '%s' "
+ "failed\n", argv[0], fname);
+ break;
+ }
+ fname = argv[++optind];
+ } while (fname != NULL);
return result;
}
time(&t);
optind = 0;
+ /* when getopt_long_only() hits '!' it returns 1 and puts "!" in optarg */
while ((c = getopt_long_only(argc, argv, "-A:C:D:g:G:M:n:PpO:qrs:t:u:U:v",
long_opts, NULL)) >= 0) {
xtime = NULL;
if (neg_opt)
--neg_opt;
/* '!' is part of option */
+ /* when getopt_long_only() finds a string which is not
+ * an option nor a known option argument it returns 1
+ * in that case if we already have found pathstart and pathend
+ * (i.e. we have the list of pathnames),
+ * the only supported value is "!"
+ */
isoption = (c != 1) || (strcmp(optarg, "!") == 0);
if (!isoption && pathend != -1) {
fprintf(stderr, "err: %s: filename|dirname must either "
/* Long options. */
break;
case 1:
+ /* unknown; opt is "!" or path component,
+ * checking done above.
+ */
if (strcmp(optarg, "!") == 0)
neg_opt = 2;
break;
break;
case FIND_POOL_OPT:
new_fashion = 1;
- if (strlen(optarg) > MAXPOOLNAME) {
+ if (strlen(optarg) > LOV_MAXPOOLNAME) {
fprintf(stderr,
"Pool name %s is too long"
" (max is %d)\n", optarg,
- MAXPOOLNAME);
+ LOV_MAXPOOLNAME);
return -1;
}
/* we do check for empty pool because empty pool
* is used to find V1 lov attributes */
- strncpy(param.poolname, optarg, MAXPOOLNAME);
- param.poolname[MAXPOOLNAME] = '\0';
+ strncpy(param.poolname, optarg, LOV_MAXPOOLNAME);
+ param.poolname[LOV_MAXPOOLNAME] = '\0';
param.exclude_pool = !!neg_opt;
param.check_pool = 1;
break;
strcpy(buf, (char *)optarg);
if (param.num_alloc_obds == 0) {
- param.obduuid = (struct obd_uuid *)malloc(FIND_MAX_OSTS *
+ param.obduuid = malloc(FIND_MAX_OSTS *
sizeof(struct obd_uuid));
if (param.obduuid == NULL)
return -ENOMEM;
return rc;
}
+static int lfs_path2fid(int argc, char **argv)
+{
+ char *path;
+ unsigned long long seq;
+ unsigned long oid, ver;
+ int rc;
+
+ if (argc != 2)
+ return CMD_HELP;
+
+ path = argv[1];
+ rc = llapi_path2fid(path, &seq, &oid, &ver);
+ if (rc) {
+ fprintf(stderr, "error: can't get fid for %s\n", path);
+ return rc;
+ }
+
+ printf("%llu:%lu", seq, oid);
+ if (ver)
+ printf(":%lu", ver);
+
+ printf("\n");
+
+ return 0;
+}
+
#define COOK(value) \
({ \
int radix = 0; \