Whamcloud - gitweb
LU-10260 hsm: enable max archive_id posix copytool
[fs/lustre-release.git] / lustre / utils / lhsmtool_posix.c
index d3633d6..05036af 100644 (file)
@@ -88,7 +88,7 @@ struct options {
        int                      o_verbose;
        int                      o_copy_xattrs;
        int                      o_archive_cnt;
-       int                      o_archive_id[LL_HSM_MAX_ARCHIVE];
+       int                      o_archive_id[LL_HSM_MAX_ARCHIVE + 1];
        int                      o_report_int;
        unsigned long long       o_bandwidth;
        size_t                   o_chunk_size;
@@ -258,17 +258,28 @@ static int ct_parseopts(int argc, char * const *argv)
        while ((c = getopt_long(argc, argv, "A:b:c:f:hiMp:qru:v",
                                long_opts, NULL)) != -1) {
                switch (c) {
-               case 'A':
-                       if ((opt.o_archive_cnt >= LL_HSM_MAX_ARCHIVE) ||
-                           (atoi(optarg) >= LL_HSM_MAX_ARCHIVE)) {
-                               rc = -E2BIG;
+               case 'A': {
+                       char *end = NULL;
+                       int val = strtol(optarg, &end, 10);
+
+                       if (*end != '\0') {
+                               rc = -EINVAL;
+                               CT_ERROR(rc, "invalid archive-id: '%s'",
+                                        optarg);
+                               return rc;
+                       }
+
+                       if (opt.o_archive_cnt > LL_HSM_MAX_ARCHIVE ||
+                           val > LL_HSM_MAX_ARCHIVE) {
+                               rc = -EINVAL;
                                CT_ERROR(rc, "archive number must be less"
-                                        "than %zu", LL_HSM_MAX_ARCHIVE);
+                                        " than %zu", LL_HSM_MAX_ARCHIVE + 1);
                                return rc;
                        }
-                       opt.o_archive_id[opt.o_archive_cnt] = atoi(optarg);
+                       opt.o_archive_id[opt.o_archive_cnt] = val;
                        opt.o_archive_cnt++;
                        break;
+               }
                case 'b': /* -b and -c have both a number with unit as arg */
                case 'c':
                        unit = ONE_MB;
@@ -2001,4 +2012,3 @@ error_cleanup:
 
        return -rc;
 }
-