* (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
* alternatives
*
+ * Copyright (c) 2013, 2014, Intel Corporation.
*/
/* HSM copytool program for POSIX filesystem-based HSM's.
*
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);
* 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);
}