X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Flfs.c;h=4890fef7a65605de594502c09dca2219d47223f5;hp=0f8d8667a31eab3a2201442514fc4c62498f7306;hb=refs%2Fchanges%2F50%2F30250%2F2;hpb=311a3bb4ca735a73afc8c9086ed4cbde85f8fcda diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 0f8d866..4890fef 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -439,12 +439,14 @@ command_t cmdlist[] = { "usage: hsm_release [--filelist FILELIST] [--data DATA] ..."}, {"hsm_remove", lfs_hsm_remove, 0, "Remove file copy from external storage.\n" - "usage: hsm_remove [--filelist FILELIST] [--data DATA]\n" - " [--mntpath MOUNTPATH] [--archive NUM] ...\n" + "usage: hsm_remove [--filelist FILELIST] [--data DATA] " + "[--archive NUM]\n" + " (FILE [FILE ...] | " + "--mntpath MOUNTPATH FID [FID ...])\n" "\n" - "Note: To remove files from the archive that have been deleted on\n" - "Lustre, set mntpath and optionally archive. In that case, all the\n" - "positional arguments and entries in the file list must be FIDs." + "Note: To remove an archived copy of a file already deleted from a " + "Lustre FS, the\n" + "--mntpath option and a list of FIDs must be specified" }, {"hsm_cancel", lfs_hsm_cancel, 0, "Cancel requests related to specified files.\n" @@ -878,18 +880,22 @@ static int lfs_component_del(char *fname, __u32 comp_id, __u32 flags) /* LCME_FL_INIT is the only supported flag in PFL */ if (flags != 0) { if (flags & ~LCME_KNOWN_FLAGS) { - fprintf(stderr, "Invalid component flags %#x\n", flags); + fprintf(stderr, + "%s setstripe: bad component flags %#x\n", + progname, flags); return -EINVAL; } } else if (comp_id > LCME_ID_MAX) { - fprintf(stderr, "Invalid component id %u\n", comp_id); + fprintf(stderr, "%s setstripe: bad component id %u\n", + progname, comp_id); return -EINVAL; } rc = llapi_layout_file_comp_del(fname, comp_id, flags); if (rc) - fprintf(stderr, "Delete component %#x from %s failed. %s\n", - comp_id, fname, strerror(errno)); + fprintf(stderr, + "%s setstripe: cannot delete component %#x from '%s': %s\n", + progname, comp_id, fname, strerror(errno)); return rc; } @@ -1674,14 +1680,19 @@ static int adjust_first_extent(char *fname, struct llapi_layout *layout) uint64_t start, end, stripe_size, prev_end = 0; int rc; - if (layout == NULL) + if (layout == NULL) { + fprintf(stderr, + "%s setstripe: layout must be specified\n", + progname); return -EINVAL; + } errno = 0; head = llapi_layout_get_by_path(fname, 0); if (head == NULL) { - fprintf(stderr, "Read layout from %s failed. %s\n", - fname, strerror(errno)); + fprintf(stderr, + "%s setstripe: cannot read layout from '%s': %s\n", + progname, fname, strerror(errno)); return -EINVAL; } else if (errno == ENODATA) { /* file without LOVEA, this component-add will be turned @@ -1689,16 +1700,16 @@ static int adjust_first_extent(char *fname, struct llapi_layout *layout) llapi_layout_free(head); return -ENODATA; } else if (!llapi_layout_is_composite(head)) { - fprintf(stderr, "'%s' isn't a composite file.\n", - fname); + fprintf(stderr, "%s setstripe: '%s' not a composite file\n", + progname, fname); llapi_layout_free(head); return -EINVAL; } rc = llapi_layout_comp_extent_get(head, &start, &prev_end); if (rc) { - fprintf(stderr, "Get prev extent failed. %s\n", - strerror(errno)); + fprintf(stderr, "%s setstripe: cannot get prev extent: %s\n", + progname, strerror(errno)); llapi_layout_free(head); return rc; } @@ -1708,42 +1719,46 @@ static int adjust_first_extent(char *fname, struct llapi_layout *layout) /* Make sure we use the first component of the layout to be added. */ rc = llapi_layout_comp_use(layout, LLAPI_LAYOUT_COMP_USE_FIRST); if (rc < 0) { - fprintf(stderr, "Move component cursor failed. %s\n", - strerror(errno)); + fprintf(stderr, + "%s setstripe: cannot move component cursor: %s\n", + progname, strerror(errno)); return rc; } rc = llapi_layout_comp_extent_get(layout, &start, &end); if (rc) { - fprintf(stderr, "Get extent failed. %s\n", strerror(errno)); + fprintf(stderr, "%s setstripe: cannot get extent: %s\n", + progname, strerror(errno)); return rc; } if (start > prev_end || end <= prev_end) { - fprintf(stderr, "First extent to be set [%lu, %lu) isn't " - "adjacent with the existing file extent end: %lu\n", - start, end, prev_end); + fprintf(stderr, + "%s setstripe: first extent [%lu, %lu) not adjacent with extent end %lu\n", + progname, start, end, prev_end); return -EINVAL; } rc = llapi_layout_stripe_size_get(layout, &stripe_size); if (rc) { - fprintf(stderr, "Get stripe size failed. %s\n", - strerror(errno)); + fprintf(stderr, "%s setstripe: cannot get stripe size: %s\n", + progname, strerror(errno)); return rc; } if (stripe_size != LLAPI_LAYOUT_DEFAULT && (prev_end & (stripe_size - 1))) { - fprintf(stderr, "Stripe size %lu not aligned with %lu\n", - stripe_size, prev_end); + fprintf(stderr, + "%s setstripe: stripe size %lu not aligned with %lu\n", + progname, stripe_size, prev_end); return -EINVAL; } rc = llapi_layout_comp_extent_set(layout, prev_end, end); if (rc) { - fprintf(stderr, "Set component extent [%lu, %lu) failed. %s\n", - prev_end, end, strerror(errno)); + fprintf(stderr, + "%s setstripe: cannot set component extent [%lu, %lu): %s\n", + progname, prev_end, end, strerror(errno)); return rc; } @@ -4831,19 +4846,83 @@ out: return rc ? : rc1; } +static int get_print_quota(char *mnt, char *name, struct if_quotactl *qctl, + int verbose, int quiet, bool human_readable) +{ + int rc1 = 0, rc2 = 0, rc3 = 0; + char *obd_type = (char *)qctl->obd_type; + char *obd_uuid = (char *)qctl->obd_uuid.uuid; + __u64 total_ialloc = 0, total_balloc = 0; + int inacc; + + rc1 = llapi_quotactl(mnt, qctl); + if (rc1 < 0) { + switch (rc1) { + case -ESRCH: + fprintf(stderr, "%s quotas are not enabled.\n", + qtype_name(qctl->qc_type)); + goto out; + case -EPERM: + fprintf(stderr, "Permission denied.\n"); + case -ENODEV: + case -ENOENT: + /* We already got error message. */ + goto out; + default: + fprintf(stderr, "Unexpected quotactl error: %s\n", + strerror(-rc1)); + } + } + + if (qctl->qc_cmd == LUSTRE_Q_GETQUOTA && !quiet) + print_quota_title(name, qctl, human_readable); + + if (rc1 && *obd_type) + fprintf(stderr, "%s %s ", obd_type, obd_uuid); + + if (qctl->qc_valid != QC_GENERAL) + mnt = ""; + + inacc = (qctl->qc_cmd == LUSTRE_Q_GETQUOTA) && + ((qctl->qc_dqblk.dqb_valid & (QIF_LIMITS|QIF_USAGE)) != + (QIF_LIMITS|QIF_USAGE)); + + print_quota(mnt, qctl, QC_GENERAL, rc1, human_readable); + + if (qctl->qc_valid == QC_GENERAL && qctl->qc_cmd != LUSTRE_Q_GETINFO && + verbose) { + char strbuf[STRBUF_LEN]; + + rc2 = print_obd_quota(mnt, qctl, 1, human_readable, + &total_ialloc); + rc3 = print_obd_quota(mnt, qctl, 0, human_readable, + &total_balloc); + kbytes2str(total_balloc, strbuf, sizeof(strbuf), + human_readable); + printf("Total allocated inode limit: %ju, total " + "allocated block limit: %s\n", (uintmax_t)total_ialloc, + strbuf); + } + + if (rc1 || rc2 || rc3 || inacc) + printf("Some errors happened when getting quota info. " + "Some devices may be not working or deactivated. " + "The data in \"[]\" is inaccurate.\n"); +out: + return rc1; + +} + static int lfs_quota(int argc, char **argv) { int c; char *mnt, *name = NULL; struct if_quotactl qctl = { .qc_cmd = LUSTRE_Q_GETQUOTA, .qc_type = ALLQUOTA }; - char *obd_type = (char *)qctl.obd_type; char *obd_uuid = (char *)qctl.obd_uuid.uuid; - int rc = 0, rc1 = 0, rc2 = 0, rc3 = 0, - verbose = 0, pass = 0, quiet = 0, inacc; + int rc = 0, rc1 = 0, verbose = 0, quiet = 0; char *endptr; __u32 valid = QC_GENERAL, idx = 0; - __u64 total_ialloc = 0, total_balloc = 0; bool human_readable = false; int qtype; @@ -4898,29 +4977,28 @@ quota_type: /* current uid/gid info for "lfs quota /path/to/lustre/mount" */ if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA && qctl.qc_type == ALLQUOTA && optind == argc - 1) { -all_output: - memset(&qctl, 0, sizeof(qctl)); /* spoiled by print_*_quota */ + qctl.qc_cmd = LUSTRE_Q_GETQUOTA; qctl.qc_valid = valid; qctl.qc_idx = idx; - qctl.qc_type = pass; - switch (qctl.qc_type) { - case USRQUOTA: - qctl.qc_id = geteuid(); - rc = uid2name(&name, qctl.qc_id); - break; - case GRPQUOTA: - qctl.qc_id = getegid(); - rc = gid2name(&name, qctl.qc_id); - break; - default: - rc = -ENOTSUP; - pass++; - goto out; + + for (qtype = USRQUOTA; qtype <= GRPQUOTA; qtype++) { + qctl.qc_type = qtype; + if (qtype == USRQUOTA) { + qctl.qc_id = geteuid(); + rc = uid2name(&name, qctl.qc_id); + } else { + qctl.qc_id = getegid(); + rc = gid2name(&name, qctl.qc_id); + } + if (rc) + name = ""; + mnt = argv[optind]; + rc1 = get_print_quota(mnt, name, &qctl, verbose, quiet, + human_readable); + if (rc1 && !rc) + rc = rc1; } - if (rc) - name = ""; - pass++; /* lfs quota -u username /path/to/lustre/mount */ } else if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) { /* options should be followed by u/g-name and mntpoint */ @@ -4952,71 +5030,15 @@ all_output: return CMD_HELP; } } + mnt = argv[optind]; + 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"); return CMD_HELP; } - mnt = argv[optind]; - rc1 = llapi_quotactl(mnt, &qctl); - if (rc1 < 0) { - switch (rc1) { - case -ESRCH: - fprintf(stderr, "%s quotas are not enabled.\n", - qtype_name(qctl.qc_type)); - goto out; - case -EPERM: - fprintf(stderr, "Permission denied.\n"); - case -ENODEV: - case -ENOENT: - /* We already got error message. */ - goto out; - default: - fprintf(stderr, "Unexpected quotactl error: %s\n", - strerror(-rc1)); - } - } - - if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA && !quiet) - print_quota_title(name, &qctl, human_readable); - - if (rc1 && *obd_type) - fprintf(stderr, "%s %s ", obd_type, obd_uuid); - - if (qctl.qc_valid != QC_GENERAL) - mnt = ""; - - inacc = (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) && - ((qctl.qc_dqblk.dqb_valid & (QIF_LIMITS|QIF_USAGE)) != - (QIF_LIMITS|QIF_USAGE)); - - print_quota(mnt, &qctl, QC_GENERAL, rc1, human_readable); - - if (qctl.qc_valid == QC_GENERAL && qctl.qc_cmd != LUSTRE_Q_GETINFO && - verbose) { - char strbuf[STRBUF_LEN]; - - rc2 = print_obd_quota(mnt, &qctl, 1, human_readable, - &total_ialloc); - rc3 = print_obd_quota(mnt, &qctl, 0, human_readable, - &total_balloc); - kbytes2str(total_balloc, strbuf, sizeof(strbuf), - human_readable); - printf("Total allocated inode limit: %ju, total " - "allocated block limit: %s\n", (uintmax_t)total_ialloc, - strbuf); - } - - if (rc1 || rc2 || rc3 || inacc) - printf("Some errors happened when getting quota info. " - "Some devices may be not working or deactivated. " - "The data in \"[]\" is inaccurate.\n"); - -out: - if (pass > 0 && pass < LL_MAXQUOTAS) - goto all_output; - - return rc1; + return rc; } #endif /* HAVE_SYS_QUOTA_H! */