+static int lfs_getstripe(int argc, char **argv)
+{
+ struct find_param param = { 0 };
+ return lfs_getstripe_internal(argc, argv, ¶m);
+}
+
+/* functions */
+static int lfs_getdirstripe(int argc, char **argv)
+{
+ struct find_param param = { 0 };
+
+ param.get_lmv = 1;
+ return lfs_getstripe_internal(argc, argv, ¶m);
+}
+
+/* functions */
+static int lfs_setdirstripe(int argc, char **argv)
+{
+ char *dname;
+ int result;
+ unsigned int stripe_offset = -1;
+ unsigned int stripe_count = 1;
+ enum lmv_hash_type hash_type;
+ char *end;
+ int c;
+ char *stripe_offset_opt = NULL;
+ char *stripe_count_opt = NULL;
+ char *stripe_hash_opt = NULL;
+ char *mode_opt = NULL;
+ int default_stripe = 0;
+ mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
+ mode_t previous_mode = 0;
+
+ struct option long_opts[] = {
+ {"count", required_argument, 0, 'c'},
+ {"index", required_argument, 0, 'i'},
+ {"mode", required_argument, 0, 'm'},
+ {"hash-type", required_argument, 0, 't'},
+ {"default_stripe", no_argument, 0, 'D'},
+ {0, 0, 0, 0}
+ };
+
+ optind = 0;
+
+ while ((c = getopt_long(argc, argv, "c:Di:m:t:", long_opts,
+ NULL)) >= 0) {
+ switch (c) {
+ case 0:
+ /* Long options. */
+ break;
+ case 'c':
+ stripe_count_opt = optarg;
+ break;
+ case 'D':
+ default_stripe = 1;
+ break;
+ case 'i':
+ stripe_offset_opt = optarg;
+ break;
+ case 'm':
+ mode_opt = optarg;
+ break;
+ case 't':
+ stripe_hash_opt = optarg;
+ break;
+ default:
+ fprintf(stderr, "error: %s: option '%s' "
+ "unrecognized\n",
+ argv[0], argv[optind - 1]);
+ return CMD_HELP;
+ }
+ }
+
+ if (optind == argc) {
+ fprintf(stderr, "error: %s: missing dirname\n",
+ argv[0]);
+ return CMD_HELP;
+ }
+
+ if (stripe_offset_opt == NULL && stripe_count_opt == NULL) {
+ fprintf(stderr, "error: %s: missing stripe offset and count.\n",
+ argv[0]);
+ return CMD_HELP;
+ }
+
+ if (stripe_offset_opt != NULL) {
+ /* get the stripe offset */
+ stripe_offset = strtoul(stripe_offset_opt, &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
+ argv[0], stripe_offset_opt);
+ return CMD_HELP;
+ }
+ }
+
+ if (mode_opt != NULL) {
+ mode = strtoul(mode_opt, &end, 8);
+ if (*end != '\0') {
+ fprintf(stderr, "error: %s: bad mode '%s'\n",
+ argv[0], mode_opt);
+ return CMD_HELP;
+ }
+ previous_mode = umask(0);
+ }
+
+ if (stripe_hash_opt == NULL ||
+ strcmp(stripe_hash_opt, LMV_HASH_NAME_FNV_1A_64) == 0) {
+ hash_type = LMV_HASH_TYPE_FNV_1A_64;
+ } else if (strcmp(stripe_hash_opt, LMV_HASH_NAME_ALL_CHARS) == 0) {
+ hash_type = LMV_HASH_TYPE_ALL_CHARS;
+ } else {
+ fprintf(stderr, "error: %s: bad stripe hash type '%s'\n",
+ argv[0], stripe_hash_opt);
+ return CMD_HELP;
+ }
+
+ /* get the stripe count */
+ if (stripe_count_opt != NULL) {
+ stripe_count = strtoul(stripe_count_opt, &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "error: %s: bad stripe count '%s'\n",
+ argv[0], stripe_count_opt);
+ return CMD_HELP;
+ }
+ }
+
+ dname = argv[optind];
+ do {
+ if (default_stripe == 1) {
+ result = llapi_dir_set_default_lmv_stripe(dname,
+ stripe_offset, stripe_count,
+ hash_type, NULL);
+ } else {
+ result = llapi_dir_create_pool(dname, mode,
+ stripe_offset,
+ stripe_count, hash_type,
+ NULL);
+ }
+
+ if (result) {
+ fprintf(stderr, "error: %s: create stripe dir '%s' "
+ "failed\n", argv[0], dname);
+ break;
+ }
+ dname = argv[++optind];
+ } while (dname != NULL);
+
+ if (mode_opt != NULL)
+ umask(previous_mode);
+
+ return result;
+}
+
+/* functions */
+static int lfs_rmentry(int argc, char **argv)
+{
+ char *dname;
+ int index;
+ int result = 0;
+
+ if (argc <= 1) {
+ fprintf(stderr, "error: %s: missing dirname\n",
+ argv[0]);
+ return CMD_HELP;
+ }
+
+ index = 1;
+ dname = argv[index];
+ while (dname != NULL) {
+ result = llapi_direntry_remove(dname);
+ if (result) {
+ fprintf(stderr, "error: %s: remove dir entry '%s' "
+ "failed\n", argv[0], dname);
+ break;
+ }
+ dname = argv[++index];
+ }
+ return result;
+}
+
+static int lfs_mv(int argc, char **argv)
+{
+ struct find_param param = {
+ .fp_max_depth = -1,
+ .mdtindex = -1,
+ };
+ char *end;
+ int c;
+ int rc = 0;
+ struct option long_opts[] = {
+ {"--mdt-index", required_argument, 0, 'M'},
+ {"verbose", no_argument, 0, 'v'},
+ {0, 0, 0, 0}
+ };
+
+ while ((c = getopt_long(argc, argv, "M:v", long_opts, NULL)) != -1) {
+ switch (c) {
+ case 'M': {
+ param.mdtindex = strtoul(optarg, &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "%s: invalid MDT index'%s'\n",
+ argv[0], optarg);
+ return CMD_HELP;
+ }
+ break;
+ }
+ case 'v': {
+ param.verbose = VERBOSE_DETAIL;
+ break;
+ }
+ default:
+ fprintf(stderr, "error: %s: unrecognized option '%s'\n",
+ argv[0], argv[optind - 1]);
+ return CMD_HELP;
+ }
+ }
+
+ if (param.mdtindex == -1) {
+ fprintf(stderr, "%s MDT index must be indicated\n", argv[0]);
+ return CMD_HELP;
+ }
+
+ if (optind >= argc) {
+ fprintf(stderr, "%s missing operand path\n", argv[0]);
+ return CMD_HELP;
+ }
+
+ param.migrate = 1;
+ rc = llapi_mv(argv[optind], ¶m);
+ if (rc != 0)
+ fprintf(stderr, "cannot migrate '%s' to MDT%04x: %s\n",
+ argv[optind], param.mdtindex, strerror(-rc));
+ return rc;
+}
+