Whamcloud - gitweb
LU-4020 hsm: allow copytool event monitoring with JSON
[fs/lustre-release.git] / lustre / utils / lhsmtool_posix.c
index ec5f305..c057e68 100644 (file)
@@ -78,6 +78,7 @@ struct options {
        unsigned long long       o_bandwidth;
        size_t                   o_chunk_size;
        enum ct_action           o_action;
+       char                    *o_event_fifo;
        char                    *o_mnt;
        char                    *o_hsm_root;
        char                    *o_src; /* for import, or rebind */
@@ -171,6 +172,7 @@ static void usage(const char *name, int rc)
        "   --dry-run                 Don't run, just show what would be done\n"
        "   -c, --chunk-size <sz>     I/O size used during data copy\n"
        "                             (unit can be used, default is MB)\n"
+       "   -f, --event-fifo <path>   Write events stream to fifo\n"
        "   -p, --hsm-root <path>     Target HSM mount point\n"
        "   -q, --quiet               Produce less verbose output\n"
        "   -u, --update-interval <s> Interval between progress reports sent\n"
@@ -191,6 +193,8 @@ static int ct_parseopts(int argc, char * const *argv)
                {"chunk-size",     required_argument, NULL,                'c'},
                {"chunk_size",     required_argument, NULL,                'c'},
                {"daemon",         no_argument,       &opt.o_daemonize,     1},
+               {"event-fifo",     required_argument, NULL,                'f'},
+               {"event_fifo",     required_argument, NULL,                'f'},
                {"dry-run",        no_argument,       &opt.o_dry_run,       1},
                {"help",           no_argument,       NULL,                'h'},
                {"hsm-root",       required_argument, NULL,                'p'},
@@ -216,7 +220,7 @@ static int ct_parseopts(int argc, char * const *argv)
        unsigned long long       unit;
 
        optind = 0;
-       while ((c = getopt_long(argc, argv, "A:b:c:hiMp:qru:v",
+       while ((c = getopt_long(argc, argv, "A:b:c:f:hiMp:qru:v",
                                long_opts, NULL)) != -1) {
                switch (c) {
                case 'A':
@@ -244,6 +248,9 @@ static int ct_parseopts(int argc, char * const *argv)
                        else
                                opt.o_bandwidth = value;
                        break;
+               case 'f':
+                       opt.o_event_fifo = optarg;
+                       break;
                case 'h':
                        usage(argv[0], 0);
                case 'i':
@@ -560,9 +567,12 @@ static int ct_copy_data(struct hsm_copyaction_private *hcp, const char *src,
                return rc;
        }
 
+       /* Don't read beyond a given extent */
+       length = min(hai->hai_extent.length, src_st.st_size);
+
        he.offset = offset;
        he.length = 0;
-       rc = llapi_hsm_action_progress(hcp, &he, 0);
+       rc = llapi_hsm_action_progress(hcp, &he, length, 0);
        if (rc < 0) {
                /* Action has been canceled or something wrong
                 * is happening. Stop copying data. */
@@ -572,8 +582,6 @@ static int ct_copy_data(struct hsm_copyaction_private *hcp, const char *src,
        }
 
        errno = 0;
-       /* Don't read beyond a given extent */
-       length = min(hai->hai_extent.length, src_st.st_size);
 
        buf = malloc(opt.o_chunk_size);
        if (buf == NULL) {
@@ -618,7 +626,7 @@ static int ct_copy_data(struct hsm_copyaction_private *hcp, const char *src,
                        last_print_time = time(0);
                        CT_TRACE("%%"LPU64" ", 100 * write_total / length);
                        he.length = write_total;
-                       rc = llapi_hsm_action_progress(hcp, &he, 0);
+                       rc = llapi_hsm_action_progress(hcp, &he, length, 0);
                        if (rc < 0) {
                                /* Action has been canceled or something wrong
                                 * is happening. Stop copying data. */
@@ -1707,6 +1715,15 @@ static int ct_run(void)
 
        setbuf(stdout, NULL);
 
+       if (opt.o_event_fifo != NULL) {
+               rc = llapi_hsm_register_event_fifo(opt.o_event_fifo);
+               if (rc < 0) {
+                       CT_ERROR(rc, "failed to register event fifo");
+                       return rc;
+               }
+               llapi_error_callback_set(llapi_hsm_log_error);
+       }
+
        rc = llapi_hsm_copytool_register(&ctdata, opt.o_mnt, 0,
                                         opt.o_archive_cnt, opt.o_archive_id);
        if (rc < 0) {
@@ -1780,6 +1797,8 @@ static int ct_run(void)
        }
 
        llapi_hsm_copytool_unregister(&ctdata);
+       if (opt.o_event_fifo != NULL)
+               llapi_hsm_unregister_event_fifo(opt.o_event_fifo);
 
        return rc;
 }