- mntdir[0] = '\0'; /* avoid matching in next loop */
- }
-
- return rc;
-}
-
-static int lfs_getname(int argc, char **argv)
-{
- char mntdir[PATH_MAX] = "", path[PATH_MAX] = "", fsname[PATH_MAX] = "";
- int rc = 0, index = 0, c;
- char buf[sizeof(struct obd_uuid)];
-
- optind = 0;
- while ((c = getopt(argc, argv, "h")) != -1)
- return CMD_HELP;
-
- if (optind == argc) { /* no paths specified, get all paths. */
- while (!llapi_search_mounts(path, index++, mntdir, fsname)) {
- rc = llapi_getname(mntdir, buf, sizeof(buf));
- if (rc < 0) {
- fprintf(stderr,
- "cannot get name for `%s': %s\n",
- mntdir, strerror(-rc));
- break;
- }
-
- printf("%s %s\n", buf, mntdir);
-
- path[0] = fsname[0] = mntdir[0] = 0;
- }
- } else { /* paths specified, only attempt to search these. */
- for (; optind < argc; optind++) {
- rc = llapi_getname(argv[optind], buf, sizeof(buf));
- if (rc < 0) {
- fprintf(stderr,
- "cannot get name for `%s': %s\n",
- argv[optind], strerror(-rc));
- break;
- }
-
- printf("%s %s\n", buf, argv[optind]);
- }
- }
- return rc;
-}
-
-static int lfs_check(int argc, char **argv)
-{
- int rc;
- char mntdir[PATH_MAX] = {'\0'};
- int num_types = 1;
- char *obd_types[2];
- char obd_type1[4];
- char obd_type2[4];
-
- if (argc != 2)
- return CMD_HELP;
-
- obd_types[0] = obd_type1;
- obd_types[1] = obd_type2;
-
- if (strcmp(argv[1], "osts") == 0) {
- strcpy(obd_types[0], "osc");
- } else if (strcmp(argv[1], "mds") == 0) {
- strcpy(obd_types[0], "mdc");
- } else if (strcmp(argv[1], "servers") == 0) {
- num_types = 2;
- strcpy(obd_types[0], "osc");
- strcpy(obd_types[1], "mdc");
- } else {
- fprintf(stderr, "error: %s: option '%s' unrecognized\n",
- argv[0], argv[1]);
- return CMD_HELP;
- }
-
- rc = llapi_search_mounts(NULL, 0, mntdir, NULL);
- if (rc < 0 || mntdir[0] == '\0') {
- fprintf(stderr, "No suitable Lustre mount found\n");
- return rc;
- }
-
- rc = llapi_target_check(num_types, obd_types, mntdir);
- if (rc)
- fprintf(stderr, "error: %s: %s status failed\n",
- argv[0],argv[1]);
-
- return rc;
-
-}
-
-static int lfs_join(int argc, char **argv)
-{
- fprintf(stderr, "join two lustre files into one.\n"
- "obsolete, HEAD does not support it anymore.\n");
- return 0;
-}
-
-#ifdef HAVE_SYS_QUOTA_H
-static int lfs_quotacheck(int argc, char **argv)
-{
- int c, check_type = 0;
- char *mnt;
- struct if_quotacheck qchk;
- struct if_quotactl qctl;
- char *obd_type = (char *)qchk.obd_type;
- int rc;
-
- memset(&qchk, 0, sizeof(qchk));
-
- optind = 0;
- while ((c = getopt(argc, argv, "gu")) != -1) {
- switch (c) {
- case 'u':
- check_type |= 0x01;
- break;
- case 'g':
- check_type |= 0x02;
- break;
- default:
- fprintf(stderr, "error: %s: option '-%c' "
- "unrecognized\n", argv[0], c);
- return CMD_HELP;
- }
- }
-
- if (check_type)
- check_type--;
- else /* do quotacheck for both user & group quota by default */
- check_type = 0x02;
-
- if (argc == optind)
- return CMD_HELP;
-
- mnt = argv[optind];
-
- rc = llapi_quotacheck(mnt, check_type);
- if (rc == -EOPNOTSUPP) {
- fprintf(stderr, "error: quotacheck not supported by the quota "
- "master.\nPlease note that quotacheck is deprecated as "
- "of lustre 2.4.0 since space accounting is always "
- "enabled.\nFilesystems not formatted with 2.4 utils or "
- "beyond can be upgraded with tunefs.lustre --quota.\n");
- return rc;
- } else if (rc) {
- fprintf(stderr, "quotacheck failed: %s\n", strerror(-rc));
- return rc;
- }
-
- rc = llapi_poll_quotacheck(mnt, &qchk);
- if (rc) {
- if (*obd_type)
- fprintf(stderr, "%s %s ", obd_type,
- obd_uuid2str(&qchk.obd_uuid));
- fprintf(stderr, "quota check failed: %s\n", strerror(-rc));
- return rc;
- }
-
- memset(&qctl, 0, sizeof(qctl));
- qctl.qc_cmd = LUSTRE_Q_QUOTAON;
- qctl.qc_type = check_type;
- rc = llapi_quotactl(mnt, &qctl);
- if (rc && rc != -EALREADY) {
- if (*obd_type)
- fprintf(stderr, "%s %s ", (char *)qctl.obd_type,
- obd_uuid2str(&qctl.obd_uuid));
- fprintf(stderr, "%s turn on quota failed: %s\n",
- argv[0], strerror(-rc));
- return rc;
- }
-
- return 0;
-}
-
-static int lfs_quotaon(int argc, char **argv)
-{
- int c;
- char *mnt;
- struct if_quotactl qctl;
- char *obd_type = (char *)qctl.obd_type;
- int rc;
-
- memset(&qctl, 0, sizeof(qctl));
- qctl.qc_cmd = LUSTRE_Q_QUOTAON;
-
- optind = 0;
- while ((c = getopt(argc, argv, "fgu")) != -1) {
- switch (c) {
- case 'u':
- qctl.qc_type |= 0x01;
- break;
- case 'g':
- qctl.qc_type |= 0x02;
- break;
- case 'f':
- qctl.qc_cmd = LUSTRE_Q_QUOTAOFF;
- break;
- default:
- fprintf(stderr, "error: %s: option '-%c' "
- "unrecognized\n", argv[0], c);
- return CMD_HELP;
- }