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 */
" each line of <list_file> consists of <old_FID> <new_FID>\n"
" %s [options] --max-sequence <fsname>\n"
" return the max fid sequence of archived files\n"
- " -A, --archive <#> Archive number (repeatable)\n"
- " -p, --hsm-root <path> Target HSM mount point\n"
- " -q, --quiet Produce less verbose output\n"
- " -v, --verbose Produce more verbose output\n"
- " -c, --chunk-size <sz> I/O size used during data copy\n"
- " (unit can be used, default is MB)\n"
- " --abort-on-error Abort operation on major error\n"
- " --dry-run Don't run, just show what would be done\n"
- " --bandwidth <bw> Limit I/O bandwidth (unit can be used\n,"
- " default is MB)\n",
+ " --abort-on-error Abort operation on major error\n"
+ " -A, --archive <#> Archive number (repeatable)\n"
+ " -b, --bandwidth <bw> Limit I/O bandwidth (unit can be used\n,"
+ " default is MB)\n"
+ " --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"
+ " to Coordinator\n"
+ " -v, --verbose Produce more verbose output\n",
cmd_name, cmd_name, cmd_name, cmd_name, cmd_name);
exit(rc);
{"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'},
{"no_xattr", no_argument, &opt.o_copy_xattrs, 0},
{"quiet", no_argument, NULL, 'q'},
{"rebind", no_argument, NULL, 'r'},
- {"report", required_argument, &opt.o_report_int, 0},
+ {"update-interval", required_argument, NULL, 'u'},
+ {"update_interval", required_argument, NULL, 'u'},
{"verbose", no_argument, NULL, 'v'},
{0, 0, 0, 0}
};
unsigned long long unit;
optind = 0;
- while ((c = getopt_long(argc, argv, "A:b:c:hiMp:qrv",
+ while ((c = getopt_long(argc, argv, "A:b:c:f:hiMp:qru:v",
long_opts, NULL)) != -1) {
switch (c) {
case 'A':
else
opt.o_bandwidth = value;
break;
+ case 'f':
+ opt.o_event_fifo = optarg;
+ break;
case 'h':
usage(argv[0], 0);
case 'i':
case 'r':
opt.o_action = CA_REBIND;
break;
+ case 'u':
+ opt.o_report_int = atoi(optarg);
+ if (opt.o_report_int < 0) {
+ rc = -EINVAL;
+ CT_ERROR(rc, "bad value for -%c '%s'", c,
+ optarg);
+ return rc;
+ }
+ break;
case 'v':
opt.o_verbose++;
break;
__u64 offset = hai->hai_extent.offset;
struct stat src_st;
struct stat dst_st;
- char *buf;
+ char *buf = NULL;
__u64 write_total = 0;
__u64 length;
time_t last_print_time = time(NULL);
CT_TRACE("going to copy data from '%s' to '%s'", src, dst);
- buf = malloc(opt.o_chunk_size);
- if (buf == NULL)
- return -ENOMEM;
-
if (fstat(src_fd, &src_st) < 0) {
rc = -errno;
CT_ERROR(rc, "cannot stat '%s'", src);
rc = lseek(src_fd, hai->hai_extent.offset, SEEK_SET);
if (rc < 0) {
- CT_ERROR(errno,
+ rc = -errno;
+ CT_ERROR(rc,
"cannot seek for read to "LPU64" (len %jd) in '%s'",
hai->hai_extent.offset, (intmax_t)src_st.st_size, src);
- rc = -errno;
- goto out;
+ 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. */
}
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) {
+ rc = -ENOMEM;
+ goto out;
+ }
CT_DEBUG("Going to copy "LPU64" bytes %s -> %s\n", length, src, dst);
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. */
rc = ftruncate(dst_fd, src_st.st_size);
if (rc < 0) {
rc = -errno;
- CT_ERROR(rc,
- "cannot truncate '%s' to size %jd",
+ CT_ERROR(rc, "cannot truncate '%s' to size %jd",
dst, (intmax_t)src_st.st_size);
err_major++;
}
}
- free(buf);
+ if (buf != NULL)
+ free(buf);
return rc;
}
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) {
}
llapi_hsm_copytool_unregister(&ctdata);
+ if (opt.o_event_fifo != NULL)
+ llapi_hsm_unregister_event_fifo(opt.o_event_fifo);
return rc;
}