Whamcloud - gitweb
LU-10260 hsm: enable max archive_id posix copytool 71/30171/6
authorThomas Stibor <t.stibor@gsi.de>
Mon, 20 Nov 2017 15:36:57 +0000 (16:36 +0100)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 3 Mar 2018 04:29:47 +0000 (04:29 +0000)
The current maximum archive-id in posix copytool is
limited to id < LL_HSM_MAX_ARCHIVE. However, the Lustre HSM
implementation checks as follows for the maximum:
if (id > LL_HSM_MAX_ARCHIVE) then flag ERROR.
Thus the number of archive id's is in the
range 0,1,..,32 = LL_HSM_MAX_ARCHIVE, and therefore
32 = LL_HSM_MAX_ARCHIVE should be included.
Note, archive-id = 0 is reserved to specify to listen to
ANY archive id and is use as default when no archive-id
option is provided.

Test-Parameters: trivial testlist=sanity-hsm
Signed-off-by: Thomas Stibor <t.stibor@gsi.de>
Change-Id: I6289c8c0e7d86b05f1f2d821b7f6b3127e5fa352
Reviewed-on: https://review.whamcloud.com/30171
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
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;
 }
-