#include <dirent.h>
#include <errno.h>
#include <getopt.h>
+#include <pthread.h>
#include <time.h>
#include <utime.h>
#include <sys/time.h>
# define NSEC_PER_SEC 1000000000UL
#endif
-/* copytool uses a 32b bitmask field to register with kuc
- * archive num = 0 => all
- * archive num from 1 to 32
- */
-#define MAX_ARCHIVE_CNT (sizeof(__u32) * 8)
-
enum ct_action {
CA_IMPORT = 1,
CA_REBIND,
int o_verbose;
int o_copy_xattrs;
int o_archive_cnt;
- int o_archive_id[MAX_ARCHIVE_CNT];
+ int o_archive_id[LL_HSM_MAX_ARCHIVE];
int o_report_int;
unsigned long long o_bandwidth;
size_t o_chunk_size;
long_opts, NULL)) != -1) {
switch (c) {
case 'A':
- if ((opt.o_archive_cnt >= MAX_ARCHIVE_CNT) ||
- (atoi(optarg) >= MAX_ARCHIVE_CNT)) {
+ if ((opt.o_archive_cnt >= LL_HSM_MAX_ARCHIVE) ||
+ (atoi(optarg) >= LL_HSM_MAX_ARCHIVE)) {
rc = -E2BIG;
CT_ERROR(rc, "archive number must be less"
- "than %zu", MAX_ARCHIVE_CNT);
+ "than %zu", LL_HSM_MAX_ARCHIVE);
return rc;
}
opt.o_archive_id[opt.o_archive_cnt] = atoi(optarg);
CT_TRACE("action=%d src=%s dst=%s mount_point=%s",
opt.o_action, opt.o_src, opt.o_dst, opt.o_mnt);
- if (!opt.o_dry_run && opt.o_hsm_root == NULL) {
+ if (opt.o_hsm_root == NULL) {
rc = -EINVAL;
CT_ERROR(rc, "must specify a root directory for the backend");
return rc;
return rc;
}
+ if (hai->hai_extent.offset > (__u64)src_st.st_size) {
+ rc = -EINVAL;
+ CT_ERROR(rc, "Trying to start reading past end ("LPU64" > "
+ "%jd) of '%s' source file", hai->hai_extent.offset,
+ (intmax_t)src_st.st_size, src);
+ return rc;
+ }
+
if (fstat(dst_fd, &dst_st) < 0) {
rc = -errno;
CT_ERROR(rc, "cannot stat '%s'", dst);
return rc;
}
- rc = lseek(src_fd, hai->hai_extent.offset, SEEK_SET);
- if (rc < 0) {
- 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);
- return rc;
- }
-
/* Don't read beyond a given extent */
- length = min(hai->hai_extent.length, src_st.st_size);
+ length = min(hai->hai_extent.length,
+ src_st.st_size - hai->hai_extent.offset);
start_time = last_bw_print = last_report_time = time(NULL);
goto fini_major;
}
- open_flags = O_WRONLY | O_NOFOLLOW | O_NONBLOCK;
+ open_flags = O_WRONLY | O_NOFOLLOW;
/* If extent is specified, don't truncate an old archived copy */
open_flags |= ((hai->hai_extent.length == -1) ? O_TRUNC : 0) | O_CREAT;
goto fini;
}
- src_fd = open(src, O_RDONLY | O_NOATIME | O_NONBLOCK | O_NOFOLLOW);
+ src_fd = open(src, O_RDONLY | O_NOATIME | O_NOFOLLOW);
if (src_fd < 0) {
rc = -errno;
CT_ERROR(rc, "cannot open '%s' for read", src);
if (line)
free(line);
- /* return 0 if all rebinds were sucessful */
+ /* return 0 if all rebinds were successful */
CT_TRACE("%u lines read from '%s', %u rebind successful", nl, list, ok);
return ok == nl ? 0 : -1;
* does successfully unmount and the mount is actually gone, but the
* mtab entry remains. So this just makes mtab happier. */
llapi_hsm_copytool_unregister(&ctdata);
+
+ /* Also remove fifo upon signal as during normal/error exit */
+ if (opt.o_event_fifo != NULL)
+ llapi_hsm_unregister_event_fifo(opt.o_event_fifo);
_exit(1);
}