Whamcloud - gitweb
LU-5170 lfs: Standardize error messages in lfs_quota() 53/28253/4
authorSteve Guminski <stephenx.guminski@intel.com>
Wed, 12 Jul 2017 15:05:50 +0000 (11:05 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 9 Jan 2018 05:35:40 +0000 (05:35 +0000)
Error and warning messages in lfs_setquota() and the llapi functions
it calls 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 <stephenx.guminski@intel.com>
Change-Id: I598be2d73a28675c06b77ca6f9fa0544ecaecc7e
Reviewed-on: https://review.whamcloud.com/28253
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Jian Yu <jian.yu@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index a5c87ef..a962de2 100644 (file)
@@ -5124,7 +5124,9 @@ static int lfs_quota(int argc, char **argv)
                        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;
@@ -5136,14 +5138,26 @@ quota_type:
                         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;
@@ -5153,12 +5167,12 @@ quota_type:
                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 &&
@@ -5189,7 +5203,9 @@ quota_type:
        } 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;
                }
 
@@ -5211,8 +5227,8 @@ quota_type:
                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;
                        }
                }
@@ -5220,7 +5236,8 @@ quota_type:
                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;
        }
 
index 86b2a83..fcc6014 100644 (file)
@@ -1131,7 +1131,7 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
        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) {
@@ -1199,7 +1199,8 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
                        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;
@@ -1207,8 +1208,8 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
                }
        } 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;
 }
 
@@ -1256,34 +1257,52 @@ int llapi_search_fsname(const char *pathname, char *fsname)
                         * 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)
@@ -4661,16 +4680,13 @@ int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
        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;
        }