From eb489300b5fafbcb5ec699098c32defe61008ed8 Mon Sep 17 00:00:00 2001 From: Steve Guminski Date: Wed, 12 Jul 2017 15:03:57 -0400 Subject: [PATCH] LU-5170 lfs: Standardize error messages in lfs_fid2path() Error messages in lfs_fid2path() are updated to a standard format. Messages are prefixed with the name of the utility and the command that caused the error. User-provided values are delimited with single quotes. Test-Parameters: trivial Signed-off-by: Steve Guminski Change-Id: I124f3e5bfad120abe701dce592da6005d53112c5 Reviewed-on: https://review.whamcloud.com/30668 Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Nunez --- lustre/utils/lfs.c | 66 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index ec86880..bf7bb98 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -6468,36 +6468,55 @@ static int lfs_fid2path(int argc, char **argv) int lnktmp; int printcur = 0; int rc = 0; + char *endptr = NULL; while ((rc = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { - switch (rc) { - case 'c': - printcur++; - break; - case 'l': - linkno = strtol(optarg, NULL, 10); - break; - case 'r': - recno = strtoll(optarg, NULL, 10); - break; - case '?': - return CMD_HELP; - default: - fprintf(stderr, "error: %s: option '%s' unrecognized\n", - argv[0], argv[optind - 1]); - return CMD_HELP; - } - } + switch (rc) { + case 'c': + printcur++; + break; + case 'l': + linkno = strtol(optarg, &endptr, 10); + if (*endptr != '\0') { + fprintf(stderr, + "%s fid2path: invalid linkno '%s'\n", + progname, optarg); + return CMD_HELP; + } + break; + case 'r': + recno = strtoll(optarg, &endptr, 10); + if (*endptr != '\0') { + fprintf(stderr, + "%s fid2path: invalid recno '%s'\n", + progname, optarg); + return CMD_HELP; + } + break; + default: + fprintf(stderr, + "%s fid2path: unrecognized option '%s'\n", + progname, argv[optind - 1]); + return CMD_HELP; + } + } - if (argc < 3) + if (argc < 3) { + fprintf(stderr, + "%s fid2path: and ... must be specified\n", + progname); return CMD_HELP; + } device = argv[optind++]; path = calloc(1, PATH_MAX); if (path == NULL) { - fprintf(stderr, "error: Not enough memory\n"); - return -errno; + rc = -errno; + fprintf(stderr, + "%s fid2path: cannot allocate memory for path: %s\n", + progname, strerror(-rc)); + return rc; } rc = 0; @@ -6512,8 +6531,9 @@ static int lfs_fid2path(int argc, char **argv) rc2 = llapi_fid2path(device, fid, path, PATH_MAX, &rectmp, &lnktmp); if (rc2 < 0) { - fprintf(stderr, "%s: error on FID %s: %s\n", - argv[0], fid, strerror(errno = -rc2)); + fprintf(stderr, + "%s fid2path: cannot find '%s': %s\n", + progname, fid, strerror(errno = -rc2)); if (rc == 0) rc = rc2; break; -- 1.8.3.1