qtype = PRJQUOTA;
quota_type:
if (qctl.qc_type != ALLQUOTA) {
- fprintf(stderr, "error: use either -u or -g\n");
+ fprintf(stderr,
+ "%s quota: only one of -u, -g, or -p may be specified\n",
+ progname);
return CMD_HELP;
}
qctl.qc_type = qtype;
valid = qctl.qc_valid = QC_UUID;
strlcpy(obd_uuid, optarg, sizeof(qctl.obd_uuid));
break;
- case 'i':
- valid = qctl.qc_valid = QC_MDTIDX;
- idx = qctl.qc_idx = atoi(optarg);
- break;
- case 'I':
- valid = qctl.qc_valid = QC_OSTIDX;
- idx = qctl.qc_idx = atoi(optarg);
- break;
+ case 'i':
+ valid = qctl.qc_valid = QC_MDTIDX;
+ idx = qctl.qc_idx = atoi(optarg);
+ if (idx == 0 && *optarg != '0') {
+ fprintf(stderr,
+ "%s quota: invalid MDT index '%s'\n",
+ progname, optarg);
+ return CMD_HELP;
+ }
+ break;
+ case 'I':
+ valid = qctl.qc_valid = QC_OSTIDX;
+ idx = qctl.qc_idx = atoi(optarg);
+ if (idx == 0 && *optarg != '0') {
+ fprintf(stderr,
+ "%s quota: invalid OST index '%s'\n",
+ progname, optarg);
+ return CMD_HELP;
+ }
+ break;
case 'v':
verbose = 1;
break;
case 'h':
human_readable = true;
break;
- default:
- fprintf(stderr, "error: %s: option '-%c' "
- "unrecognized\n", argv[0], c);
- return CMD_HELP;
- }
- }
+ default:
+ fprintf(stderr, "%s quota: unrecognized option '%s'\n",
+ progname, argv[optind - 1]);
+ return CMD_HELP;
+ }
+ }
/* current uid/gid info for "lfs quota /path/to/lustre/mount" */
if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA && qctl.qc_type == ALLQUOTA &&
} else if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) {
/* options should be followed by u/g-name and mntpoint */
if (optind + 2 != argc || qctl.qc_type == ALLQUOTA) {
- fprintf(stderr, "error: missing quota argument(s)\n");
+ fprintf(stderr,
+ "%s quota: name and mount point must be specified\n",
+ progname);
return CMD_HELP;
}
if (rc) {
qctl.qc_id = strtoul(name, &endptr, 10);
if (*endptr != '\0') {
- fprintf(stderr, "error: can't find id for name: %s\n",
- name);
+ fprintf(stderr, "%s quota: invalid id '%s'\n",
+ progname, name);
return CMD_HELP;
}
}
rc = get_print_quota(mnt, name, &qctl, verbose, quiet,
human_readable);
} else if (optind + 1 != argc || qctl.qc_type == ALLQUOTA) {
- fprintf(stderr, "error: missing quota info argument(s)\n");
+ fprintf(stderr, "%s quota: missing quota info argument(s)\n",
+ progname);
return CMD_HELP;
}
if (fp == NULL) {
rc = -EIO;
llapi_error(LLAPI_MSG_ERROR, rc,
- "setmntent(%s) failed", PROC_MOUNTS);
+ "cannot retrieve filesystem mount point");
return rc;
}
while (1) {
if (fd < 0) {
rc = -errno;
llapi_error(LLAPI_MSG_ERROR, rc,
- "error opening '%s'", mntdir);
+ "cannot open '%s': %s", mntdir,
+ strerror(-rc));
} else {
*outfd = fd;
}
} else if (want & WANT_ERROR)
llapi_err_noerrno(LLAPI_MSG_ERROR,
- "can't find fs root for '%s': %d",
- (want & WANT_PATH) ? fsname : path, rc);
+ "'%s' not on a mounted Lustre filesystem",
+ (want & WANT_PATH) ? fsname : path);
return rc;
}
* pathnames that actually exist. We go through the
* extra hurdle of dirname(getcwd() + pathname) in
* case the relative pathname contains ".." in it. */
- if (getcwd(buf, sizeof(buf) - 2) == NULL)
- return -errno;
+ if (getcwd(buf, sizeof(buf) - 2) == NULL) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "cannot get current working directory");
+ return rc;
+ }
rc = strlcat(buf, "/", sizeof(buf));
- if (rc >= sizeof(buf))
- return -E2BIG;
+ if (rc >= sizeof(buf)) {
+ rc = -E2BIG;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "invalid parent path '%s'",
+ buf);
+ return rc;
+ }
}
rc = strlcat(buf, pathname, sizeof(buf));
- if (rc >= sizeof(buf))
- return -E2BIG;
- path = realpath(buf, NULL);
- if (path == NULL) {
- ptr = strrchr(buf, '/');
- if (ptr == NULL)
- return -ENOENT;
- *ptr = '\0';
- path = realpath(buf, NULL);
- if (path == NULL) {
- rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "pathname '%s' cannot expand",
- pathname);
- return rc;
- }
- }
- }
- rc = get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL, path, -1);
- free(path);
- return rc;
+ if (rc >= sizeof(buf)) {
+ rc = -E2BIG;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "invalid path '%s'", pathname);
+ return rc;
+ }
+ path = realpath(buf, NULL);
+ if (path == NULL) {
+ ptr = strrchr(buf, '/');
+ if (ptr == NULL) {
+ llapi_error(LLAPI_MSG_ERROR |
+ LLAPI_MSG_NO_ERRNO, 0,
+ "cannot resolve path '%s'",
+ buf);
+ return -ENOENT;
+ }
+ *ptr = '\0';
+ path = realpath(buf, NULL);
+ if (path == NULL) {
+ rc = -errno;
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "cannot resolve path '%s'",
+ pathname);
+ return rc;
+ }
+ }
+ }
+ rc = get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL, path, -1);
+ free(path);
+ return rc;
}
int llapi_search_rootpath(char *pathname, const char *fsname)
int rc;
rc = llapi_search_fsname(mnt, fsname);
- if (rc) {
- llapi_err_noerrno(LLAPI_MSG_ERROR,
- "'%s' isn't on Lustre filesystem", mnt);
+ if (rc)
return rc;
- }
root = open(mnt, O_RDONLY | O_DIRECTORY);
if (root < 0) {
rc = -errno;
- llapi_error(LLAPI_MSG_ERROR, rc, "open %s failed", mnt);
+ llapi_error(LLAPI_MSG_ERROR, rc, "cannot open '%s'", mnt);
return rc;
}