4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.htm
23 * (C) Copyright 2012 Commissariat a l'energie atomique et aux energies
26 * Copyright (c) 2013, 2016, Intel Corporation.
28 /* HSM copytool program for POSIX filesystem-based HSM's.
30 * An HSM copytool daemon acts on action requests from Lustre to copy files
31 * to and from an HSM archive system. This one in particular makes regular
32 * POSIX filesystem calls to a given path, where an HSM is presumably mounted.
34 * This particular tool can also import an existing HSM archive.
55 #include <sys/xattr.h>
56 #include <sys/syscall.h>
57 #include <sys/types.h>
59 #include <libcfs/util/string.h>
60 #include <linux/lustre/lustre_fid.h>
61 #include <lustre/lustreapi.h>
64 /* Progress reporting period */
65 #define REPORT_INTERVAL_DEFAULT 30
66 /* HSM hash subdir permissions */
67 #define DIR_PERM S_IRWXU
68 /* HSM hash file permissions */
69 #define FILE_PERM (S_IRUSR | S_IWUSR)
71 #define ONE_MB 0x100000
74 # define NSEC_PER_SEC 1000000000UL
91 int o_archive_id_used;
95 unsigned long long o_bandwidth;
97 enum ct_action o_action;
102 char *o_src; /* for import, or rebind */
103 char *o_dst; /* for import, or rebind */
107 /* everything else is zeroed */
108 struct options opt = {
111 .o_verbose = LLAPI_MSG_INFO,
113 .o_report_int = REPORT_INTERVAL_DEFAULT,
114 .o_chunk_size = ONE_MB,
117 /* hsm_copytool_private will hold an open FD on the lustre mount point
118 * for us. Additionally open one on the archive FS root to make sure
119 * it doesn't drop out from under us (and remind the admin to shutdown
120 * the copytool before unmounting). */
122 static int arc_fd = -1;
124 static int err_major;
125 static int err_minor;
127 static char cmd_name[PATH_MAX];
128 static char fs_name[MAX_OBD_NAME + 1];
129 static int pid_file_fd = -1;
131 static struct hsm_copytool_private *ctdata;
133 static inline double ct_now(void)
137 gettimeofday(&tv, NULL);
139 return tv.tv_sec + 0.000001 * tv.tv_usec;
142 #define CT_ERROR(_rc, _format, ...) \
143 llapi_error(LLAPI_MSG_ERROR, _rc, \
144 "%f %s[%ld]: "_format, \
145 ct_now(), cmd_name, syscall(SYS_gettid), ## __VA_ARGS__)
147 #define CT_DEBUG(_format, ...) \
148 llapi_error(LLAPI_MSG_DEBUG | LLAPI_MSG_NO_ERRNO, 0, \
149 "%f %s[%ld]: "_format, \
150 ct_now(), cmd_name, syscall(SYS_gettid), ## __VA_ARGS__)
152 #define CT_WARN(_format, ...) \
153 llapi_error(LLAPI_MSG_WARN | LLAPI_MSG_NO_ERRNO, 0, \
154 "%f %s[%ld]: "_format, \
155 ct_now(), cmd_name, syscall(SYS_gettid), ## __VA_ARGS__)
157 #define CT_TRACE(_format, ...) \
158 llapi_error(LLAPI_MSG_INFO | LLAPI_MSG_NO_ERRNO, 0, \
159 "%f %s[%ld]: "_format, \
160 ct_now(), cmd_name, syscall(SYS_gettid), ## __VA_ARGS__)
162 static void usage(const char *name, int rc)
165 " Usage: %s [options]... <mode> <lustre_mount_point>\n"
166 "The Lustre HSM Posix copy tool can be used as a daemon or "
167 "as a command line tool\n"
168 "The Lustre HSM daemon acts on action requests from Lustre\n"
169 "to copy files to and from an HSM archive system.\n"
170 "This POSIX-flavored daemon makes regular POSIX filesystem calls\n"
171 "to an HSM mounted at a given hsm_root.\n"
172 " --daemon Daemon mode, run in background\n"
174 " --no-attr Don't copy file attributes\n"
175 " --no-shadow Don't create shadow namespace in archive\n"
176 " --no-xattr Don't copy file extended attributes\n"
177 "The Lustre HSM tool performs administrator-type actions\n"
178 "on a Lustre HSM archive.\n"
179 "This POSIX-flavored tool can link an existing HSM namespace\n"
180 "into a Lustre filesystem.\n"
182 " %s [options] --import <src> <dst> <lustre_mount_point>\n"
183 " import an archived subtree from\n"
184 " <src> (FID or relative path to hsm_root) into the Lustre\n"
186 " <dst> (absolute path)\n"
187 " %s [options] --rebind <old_FID> <new_FID> <lustre_mount_point>\n"
188 " rebind an entry in the HSM to a new FID\n"
189 " <old_FID> old FID the HSM entry is bound to\n"
190 " <new_FID> new FID to bind the HSM entry to\n"
191 " %s [options] --rebind <list_file> <lustre_mount_point>\n"
192 " perform the rebind operation for all FID in the list file\n"
193 " each line of <list_file> consists of <old_FID> <new_FID>\n"
194 " %s [options] --max-sequence <fsname>\n"
195 " return the max fid sequence of archived files\n"
196 " --abort-on-error Abort operation on major error\n"
197 " -A, --archive <#> Archive number (repeatable)\n"
198 " -b, --bandwidth <bw> Limit I/O bandwidth (unit can be used\n,"
200 " --dry-run Don't run, just show what would be done\n"
201 " -c, --chunk-size <sz> I/O size used during data copy\n"
202 " (unit can be used, default is MB)\n"
203 " -f, --event-fifo <path> Write events stream to fifo\n"
204 " -P, --pid-file=PATH Lock and write PID to PATH\n"
205 " -p, --hsm-root <path> Target HSM mount point\n"
206 " -q, --quiet Produce less verbose output\n"
207 " -u, --update-interval <s> Interval between progress reports sent\n"
209 " -v, --verbose Produce more verbose output\n",
210 cmd_name, cmd_name, cmd_name, cmd_name, cmd_name);
215 static int ct_parseopts(int argc, char * const *argv)
217 struct option long_opts[] = {
218 { .val = 1, .name = "abort-on-error",
219 .flag = &opt.o_abort_on_error, .has_arg = no_argument },
220 { .val = 1, .name = "abort_on_error",
221 .flag = &opt.o_abort_on_error, .has_arg = no_argument },
222 { .val = 'A', .name = "archive", .has_arg = required_argument },
223 { .val = 'b', .name = "bandwidth", .has_arg = required_argument },
224 { .val = 'c', .name = "chunk-size", .has_arg = required_argument },
225 { .val = 'c', .name = "chunk_size", .has_arg = required_argument },
226 { .val = 1, .name = "daemon", .has_arg = no_argument,
227 .flag = &opt.o_daemonize },
228 { .val = 'f', .name = "event-fifo", .has_arg = required_argument },
229 { .val = 'f', .name = "event_fifo", .has_arg = required_argument },
230 { .val = 1, .name = "dry-run", .has_arg = no_argument,
231 .flag = &opt.o_dry_run },
232 { .val = 'h', .name = "help", .has_arg = no_argument },
233 { .val = 'i', .name = "import", .has_arg = no_argument },
234 { .val = 'M', .name = "max-sequence", .has_arg = no_argument },
235 { .val = 'M', .name = "max_sequence", .has_arg = no_argument },
236 { .val = 0, .name = "no-attr", .has_arg = no_argument,
237 .flag = &opt.o_copy_attrs },
238 { .val = 0, .name = "no_attr", .has_arg = no_argument,
239 .flag = &opt.o_copy_attrs },
240 { .val = 0, .name = "no-shadow", .has_arg = no_argument,
241 .flag = &opt.o_shadow_tree },
242 { .val = 0, .name = "no_shadow", .has_arg = no_argument,
243 .flag = &opt.o_shadow_tree },
244 { .val = 0, .name = "no-xattr", .has_arg = no_argument,
245 .flag = &opt.o_copy_xattrs },
246 { .val = 0, .name = "no_xattr", .has_arg = no_argument,
247 .flag = &opt.o_copy_xattrs },
248 { .val = 'P', .name = "pid-file", .has_arg = required_argument },
249 { .val = 'p', .name = "hsm-root", .has_arg = required_argument },
250 { .val = 'p', .name = "hsm_root", .has_arg = required_argument },
251 { .val = 'q', .name = "quiet", .has_arg = no_argument },
252 { .val = 'r', .name = "rebind", .has_arg = no_argument },
253 { .val = 'u', .name = "update-interval",
254 .has_arg = required_argument },
255 { .val = 'u', .name = "update_interval",
256 .has_arg = required_argument },
257 { .val = 'v', .name = "verbose", .has_arg = no_argument },
260 unsigned long long value;
261 unsigned long long unit;
268 opt.o_archive_id_cnt = LL_HSM_ORIGIN_MAX_ARCHIVE;
269 opt.o_archive_id = malloc(opt.o_archive_id_cnt *
270 sizeof(*opt.o_archive_id));
271 if (opt.o_archive_id == NULL)
274 while ((c = getopt_long(argc, argv, "A:b:c:f:hiMp:P:qru:v",
275 long_opts, NULL)) != -1) {
279 int val = strtol(optarg, &end, 10);
283 CT_ERROR(rc, "invalid archive-id: '%s'",
287 /* if archiveID is zero, any archiveID is accepted */
292 free(opt.o_archive_id);
293 opt.o_archive_id = NULL;
294 opt.o_archive_id_cnt = 0;
295 opt.o_archive_id_used = 0;
297 CT_WARN("archive-id = 0 is found, any backend will be served\n");
301 /* skip the duplicated id */
302 for (i = 0; i < opt.o_archive_id_used; i++) {
303 if (opt.o_archive_id[i] == val)
306 /* extend the space */
307 if (opt.o_archive_id_used >= opt.o_archive_id_cnt) {
310 opt.o_archive_id_cnt *= 2;
311 tmp = realloc(opt.o_archive_id,
312 sizeof(*opt.o_archive_id) *
313 opt.o_archive_id_cnt);
317 opt.o_archive_id = tmp;
320 opt.o_archive_id[opt.o_archive_id_used++] = val;
323 case 'b': /* -b and -c have both a number with unit as arg */
326 if (llapi_parse_size(optarg, &value, &unit, 0) < 0) {
328 CT_ERROR(rc, "bad value for -%c '%s'", c,
333 opt.o_chunk_size = value;
335 opt.o_bandwidth = value;
338 opt.o_event_fifo = optarg;
343 opt.o_action = CA_IMPORT;
346 opt.o_action = CA_MAXSEQ;
349 opt.o_pid_file = optarg;
352 opt.o_hsm_root = optarg;
358 opt.o_action = CA_REBIND;
361 opt.o_report_int = atoi(optarg);
362 if (opt.o_report_int < 0) {
364 CT_ERROR(rc, "bad value for -%c '%s'", c,
379 switch (opt.o_action) {
381 /* src dst mount_point */
382 if (argc != optind + 3) {
384 CT_ERROR(rc, "--import requires 2 arguments");
387 opt.o_src = argv[optind++];
388 opt.o_dst = argv[optind++];
391 /* FID1 FID2 mount_point or FILE mount_point */
392 if (argc == optind + 2) {
393 opt.o_src = argv[optind++];
395 } else if (argc == optind + 3) {
396 opt.o_src = argv[optind++];
397 opt.o_dst = argv[optind++];
400 CT_ERROR(rc, "--rebind requires 1 or 2 arguments");
406 /* just mount point */
410 if (argc != optind + 1) {
412 CT_ERROR(rc, "no mount point specified");
416 opt.o_mnt = argv[optind];
419 CT_TRACE("action=%d src=%s dst=%s mount_point=%s",
420 opt.o_action, opt.o_src, opt.o_dst, opt.o_mnt);
422 if (opt.o_hsm_root == NULL) {
424 CT_ERROR(rc, "must specify a root directory for the backend");
428 if (opt.o_action == CA_IMPORT) {
429 if (opt.o_src && opt.o_src[0] == '/') {
432 "source path must be relative to HSM root");
436 if (opt.o_dst && opt.o_dst[0] != '/') {
438 CT_ERROR(rc, "destination path must be absolute");
447 static int ct_mkdir_p(const char *path)
460 while ((ptr = strchr(ptr, '/')) != NULL) {
462 rc = mkdir(saved, DIR_PERM);
464 if (rc < 0 && errno != EEXIST) {
466 CT_ERROR(rc, "cannot mkdir '%s'", path);
478 static int ct_save_stripe(int src_fd, const char *src, const char *dst)
480 char lov_file[PATH_MAX + 8];
481 char lov_buf[XATTR_SIZE_MAX];
482 struct lov_user_md *lum;
487 snprintf(lov_file, sizeof(lov_file), "%s.lov", dst);
488 CT_TRACE("saving stripe info of '%s' in %s", src, lov_file);
490 xattr_size = fgetxattr(src_fd, XATTR_LUSTRE_LOV, lov_buf,
492 if (xattr_size < 0) {
494 CT_ERROR(rc, "cannot get stripe info on '%s'", src);
498 lum = (struct lov_user_md *)lov_buf;
500 if (lum->lmm_magic == LOV_USER_MAGIC_V1 ||
501 lum->lmm_magic == LOV_USER_MAGIC_V3) {
502 /* Set stripe_offset to -1 so that it is not interpreted as a
503 * hint on restore. */
504 lum->lmm_stripe_offset = -1;
507 fd = open(lov_file, O_TRUNC | O_CREAT | O_WRONLY, FILE_PERM);
510 CT_ERROR(rc, "cannot open '%s'", lov_file);
514 rc = write(fd, lum, xattr_size);
517 CT_ERROR(rc, "cannot write %zd bytes to '%s'",
518 xattr_size, lov_file);
526 CT_ERROR(rc, "cannot close '%s'", lov_file);
538 static int ct_load_stripe(const char *src, void *lovea, size_t *lovea_size)
540 char lov_file[PATH_MAX + 4];
544 snprintf(lov_file, sizeof(lov_file), "%s.lov", src);
545 CT_TRACE("reading stripe rules from '%s' for '%s'", lov_file, src);
547 fd = open(lov_file, O_RDONLY);
549 CT_ERROR(errno, "cannot open '%s'", lov_file);
553 rc = read(fd, lovea, *lovea_size);
555 CT_ERROR(errno, "cannot read %zu bytes from '%s'",
556 *lovea_size, lov_file);
567 static int ct_restore_stripe(const char *src, const char *dst, int dst_fd,
568 const void *lovea, size_t lovea_size)
572 rc = fsetxattr(dst_fd, XATTR_LUSTRE_LOV, lovea, lovea_size,
576 CT_ERROR(rc, "cannot set lov EA on '%s'", dst);
582 static int ct_copy_data(struct hsm_copyaction_private *hcp, const char *src,
583 const char *dst, int src_fd, int dst_fd,
584 const struct hsm_action_item *hai, long hal_flags)
586 struct hsm_extent he;
587 __u64 offset = hai->hai_extent.offset;
591 __u64 write_total = 0;
592 __u64 length = hai->hai_extent.length;
593 time_t last_report_time;
595 double start_ct_now = ct_now();
596 /* Bandwidth Control */
599 time_t last_bw_print;
601 if (fstat(src_fd, &src_st) < 0) {
603 CT_ERROR(rc, "cannot stat '%s'", src);
607 if (!S_ISREG(src_st.st_mode)) {
609 CT_ERROR(rc, "'%s' is not a regular file", src);
613 if (hai->hai_extent.offset > (__u64)src_st.st_size) {
615 CT_ERROR(rc, "Trying to start reading past end (%ju > "
616 "%jd) of '%s' source file",
617 (uintmax_t)hai->hai_extent.offset,
618 (intmax_t)src_st.st_size, src);
622 if (fstat(dst_fd, &dst_st) < 0) {
624 CT_ERROR(rc, "cannot stat '%s'", dst);
628 if (!S_ISREG(dst_st.st_mode)) {
630 CT_ERROR(rc, "'%s' is not a regular file", dst);
634 /* Don't read beyond a given extent */
635 if (length > src_st.st_size - hai->hai_extent.offset)
636 length = src_st.st_size - hai->hai_extent.offset;
638 start_time = last_bw_print = last_report_time = time(NULL);
642 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
644 /* Action has been canceled or something wrong
645 * is happening. Stop copying data. */
646 CT_ERROR(rc, "progress ioctl for copy '%s'->'%s' failed",
653 buf = malloc(opt.o_chunk_size);
659 CT_TRACE("start copy of %ju bytes from '%s' to '%s'",
660 (uintmax_t)length, src, dst);
662 while (write_total < length) {
665 int chunk = (length - write_total > opt.o_chunk_size) ?
666 opt.o_chunk_size : length - write_total;
668 rsize = pread(src_fd, buf, chunk, offset);
675 CT_ERROR(rc, "cannot read from '%s'", src);
679 wsize = pwrite(dst_fd, buf, rsize, offset);
682 CT_ERROR(rc, "cannot write to '%s'", dst);
686 write_total += wsize;
690 /* sleep if needed, to honor bandwidth limits */
691 if (opt.o_bandwidth != 0) {
692 unsigned long long write_theory;
694 write_theory = (now - start_time) * opt.o_bandwidth;
696 if (write_theory < write_total) {
697 unsigned long long excess;
698 struct timespec delay;
700 excess = write_total - write_theory;
702 delay.tv_sec = excess / opt.o_bandwidth;
703 delay.tv_nsec = (excess % opt.o_bandwidth) *
704 NSEC_PER_SEC / opt.o_bandwidth;
706 if (now >= last_bw_print + opt.o_report_int) {
707 CT_TRACE("bandwith control: %lluB/s "
708 "excess=%llu sleep for "
710 (unsigned long long)opt.o_bandwidth,
711 (unsigned long long)excess,
712 (long long)delay.tv_sec,
718 rc = nanosleep(&delay, &delay);
719 } while (rc < 0 && errno == EINTR);
721 CT_ERROR(errno, "delay for bandwidth "
722 "control failed to sleep: "
723 "residual=%lld.%09lds",
724 (long long)delay.tv_sec,
732 if (now >= last_report_time + opt.o_report_int) {
733 last_report_time = now;
734 CT_TRACE("%%%ju ", (uintmax_t)(100 * write_total / length));
735 /* only give the length of the write since the last
737 he.length = offset - he.offset;
738 rc = llapi_hsm_action_progress(hcp, &he, length, 0);
740 /* Action has been canceled or something wrong
741 * is happening. Stop copying data. */
742 CT_ERROR(rc, "progress ioctl for copy"
743 " '%s'->'%s' failed", src, dst);
753 * truncate restored file
754 * size is taken from the archive this is done to support
755 * restore after a force release which leaves the file with the
756 * wrong size (can big bigger than the new size)
758 if ((hai->hai_action == HSMA_RESTORE) &&
759 (src_st.st_size < dst_st.st_size)) {
761 * make sure the file is on disk before reporting success.
763 rc = ftruncate(dst_fd, src_st.st_size);
766 CT_ERROR(rc, "cannot truncate '%s' to size %jd",
767 dst, (intmax_t)src_st.st_size);
775 CT_TRACE("copied %ju bytes in %f seconds",
776 (uintmax_t)length, ct_now() - start_ct_now);
781 /* Copy file attributes from file src to file dest */
782 static int ct_copy_attr(const char *src, const char *dst, int src_fd,
786 struct timeval times[2];
789 if (fstat(src_fd, &st) < 0) {
791 CT_ERROR(rc, "cannot stat '%s'", src);
795 times[0].tv_sec = st.st_atime;
796 times[0].tv_usec = 0;
797 times[1].tv_sec = st.st_mtime;
798 times[1].tv_usec = 0;
799 if (fchmod(dst_fd, st.st_mode) < 0 ||
800 fchown(dst_fd, st.st_uid, st.st_gid) < 0 ||
801 futimes(dst_fd, times) < 0) {
803 CT_ERROR(rc, "cannot set attributes of '%s'", src);
810 static int ct_copy_xattr(const char *src, const char *dst, int src_fd,
811 int dst_fd, bool is_restore)
813 char list[XATTR_LIST_MAX];
814 char value[XATTR_SIZE_MAX];
819 list_len = flistxattr(src_fd, list, sizeof(list));
824 while (name < list + list_len) {
825 rc = fgetxattr(src_fd, name, value, sizeof(value));
829 /* when we restore, we do not restore lustre xattr */
831 (strncmp(XATTR_TRUSTED_PREFIX, name,
832 sizeof(XATTR_TRUSTED_PREFIX) - 1) != 0)) {
833 rc = fsetxattr(dst_fd, name, value, rc, 0);
834 CT_TRACE("fsetxattr of '%s' on '%s' rc=%d (%s)",
835 name, dst, rc, strerror(errno));
836 /* lustre.* attrs aren't supported on other FS's */
837 if (rc < 0 && errno != EOPNOTSUPP) {
839 CT_ERROR(rc, "cannot set extended attribute"
845 name += strlen(name) + 1;
851 static int ct_path_lustre(char *buf, int sz, const char *mnt,
852 const struct lu_fid *fid)
854 return scnprintf(buf, sz, "%s/%s/fid/"DFID_NOBRACE, mnt,
855 dot_lustre_name, PFID(fid));
858 static int ct_path_archive(char *buf, int sz, const char *archive_dir,
859 const struct lu_fid *fid)
861 return scnprintf(buf, sz, "%s/%04x/%04x/%04x/%04x/%04x/%04x/"
862 DFID_NOBRACE, archive_dir,
863 (fid)->f_oid & 0xFFFF,
864 (fid)->f_oid >> 16 & 0xFFFF,
865 (unsigned int)((fid)->f_seq & 0xFFFF),
866 (unsigned int)((fid)->f_seq >> 16 & 0xFFFF),
867 (unsigned int)((fid)->f_seq >> 32 & 0xFFFF),
868 (unsigned int)((fid)->f_seq >> 48 & 0xFFFF),
872 static bool ct_is_retryable(int err)
874 return err == -ETIMEDOUT;
877 static int ct_begin_restore(struct hsm_copyaction_private **phcp,
878 const struct hsm_action_item *hai,
879 int mdt_index, int open_flags)
884 rc = llapi_hsm_action_begin(phcp, ctdata, hai, mdt_index, open_flags,
887 ct_path_lustre(src, sizeof(src), opt.o_mnt, &hai->hai_fid);
888 CT_ERROR(rc, "llapi_hsm_action_begin() on '%s' failed", src);
894 static int ct_begin(struct hsm_copyaction_private **phcp,
895 const struct hsm_action_item *hai)
897 /* Restore takes specific parameters. Call the same function w/ default
898 * values for all other operations. */
899 return ct_begin_restore(phcp, hai, -1, 0);
902 static int ct_fini(struct hsm_copyaction_private **phcp,
903 const struct hsm_action_item *hai, int hp_flags, int ct_rc)
905 struct hsm_copyaction_private *hcp;
909 CT_TRACE("Action completed, notifying coordinator "
910 "cookie=%#jx, FID="DFID", hp_flags=%d err=%d",
911 (uintmax_t)hai->hai_cookie, PFID(&hai->hai_fid),
914 ct_path_lustre(lstr, sizeof(lstr), opt.o_mnt, &hai->hai_fid);
916 if (phcp == NULL || *phcp == NULL) {
917 rc = llapi_hsm_action_begin(&hcp, ctdata, hai, -1, 0, true);
919 CT_ERROR(rc, "llapi_hsm_action_begin() on '%s' failed",
926 rc = llapi_hsm_action_end(phcp, &hai->hai_extent, hp_flags, abs(ct_rc));
927 if (rc == -ECANCELED)
928 CT_ERROR(rc, "completed action on '%s' has been canceled: "
929 "cookie=%#jx, FID="DFID, lstr,
930 (uintmax_t)hai->hai_cookie, PFID(&hai->hai_fid));
932 CT_ERROR(rc, "llapi_hsm_action_end() on '%s' failed", lstr);
934 CT_TRACE("llapi_hsm_action_end() on '%s' ok (rc=%d)",
940 static int ct_archive(const struct hsm_action_item *hai, const long hal_flags)
942 struct hsm_copyaction_private *hcp = NULL;
944 char dst[PATH_MAX + 4] = "";
945 char root[PATH_MAX] = "";
948 bool rename_needed = false;
954 rc = ct_begin(&hcp, hai);
958 /* we fill archive so:
960 * destination = lustre FID
962 ct_path_lustre(src, sizeof(src), opt.o_mnt, &hai->hai_dfid);
963 ct_path_archive(root, sizeof(root), opt.o_hsm_root, &hai->hai_fid);
964 if (hai->hai_extent.length == -1) {
965 /* whole file, write it to tmp location and atomically
966 * replace old archived file */
967 snprintf(dst, sizeof(dst), "%s_tmp", root);
968 /* we cannot rely on the same test because ct_copy_data()
969 * updates hai_extent.length */
970 rename_needed = true;
972 snprintf(dst, sizeof(dst), "%s", root);
975 CT_TRACE("archiving '%s' to '%s'", src, dst);
982 rc = ct_mkdir_p(dst);
984 CT_ERROR(rc, "mkdir_p '%s' failed", dst);
988 src_fd = llapi_hsm_action_get_fd(hcp);
991 CT_ERROR(rc, "cannot open '%s' for read", src);
995 open_flags = O_WRONLY | O_NOFOLLOW;
996 /* If extent is specified, don't truncate an old archived copy */
997 open_flags |= ((hai->hai_extent.length == -1) ? O_TRUNC : 0) | O_CREAT;
999 dst_fd = open(dst, open_flags, FILE_PERM);
1002 CT_ERROR(rc, "cannot open '%s' for write", dst);
1006 /* saving stripe is not critical */
1007 rc = ct_save_stripe(src_fd, src, dst);
1009 CT_ERROR(rc, "cannot save file striping info of '%s' in '%s'",
1012 rc = ct_copy_data(hcp, src, dst, src_fd, dst_fd, hai, hal_flags);
1014 CT_ERROR(rc, "data copy failed from '%s' to '%s'", src, dst);
1021 CT_ERROR(rc, "cannot flush '%s' archive file '%s'", src, dst);
1025 CT_TRACE("data archiving for '%s' to '%s' done", src, dst);
1027 /* attrs will remain on the MDS; no need to copy them, except possibly
1028 for disaster recovery */
1029 if (opt.o_copy_attrs) {
1030 rc = ct_copy_attr(src, dst, src_fd, dst_fd);
1032 CT_ERROR(rc, "cannot copy attr of '%s' to '%s'",
1036 CT_TRACE("attr file for '%s' saved to archive '%s'",
1040 /* xattrs will remain on the MDS; no need to copy them, except possibly
1041 for disaster recovery */
1042 if (opt.o_copy_xattrs) {
1043 rc = ct_copy_xattr(src, dst, src_fd, dst_fd, false);
1045 CT_ERROR(rc, "cannot copy xattr of '%s' to '%s'",
1047 rcf = rcf ? rcf : rc;
1049 CT_TRACE("xattr file for '%s' saved to archive '%s'",
1053 if (rename_needed == true) {
1054 char tmp_src[PATH_MAX + 8];
1055 char tmp_dst[PATH_MAX + 8];
1057 /* atomically replace old archived file */
1058 ct_path_archive(src, sizeof(src), opt.o_hsm_root,
1060 rc = rename(dst, src);
1063 CT_ERROR(rc, "cannot rename '%s' to '%s'", dst, src);
1066 /* rename lov file */
1067 snprintf(tmp_src, sizeof(tmp_src), "%s.lov", src);
1068 snprintf(tmp_dst, sizeof(tmp_dst), "%s.lov", dst);
1069 rc = rename(tmp_dst, tmp_src);
1071 CT_ERROR(errno, "cannot rename '%s' to '%s'",
1075 if (opt.o_shadow_tree) {
1076 /* Create a namespace of softlinks that shadows the original
1077 * Lustre namespace. This will only be current at
1078 * time-of-archive (won't follow renames).
1079 * WARNING: release won't kill these links; a manual
1080 * cleanup of dead links would be required.
1083 long long recno = -1;
1089 sprintf(src, "%s/shadow/", opt.o_hsm_root);
1091 ptr = opt.o_hsm_root;
1093 (*ptr++ == '/') ? depth-- : 0;
1095 rc = llapi_fid2path_at(opt.o_mnt_fd, &hai->hai_fid,
1097 sizeof(src) - strlen(src),
1100 CT_ERROR(rc, "cannot get FID of "DFID,
1101 PFID(&hai->hai_fid));
1102 rcf = rcf ? rcf : rc;
1106 /* Figure out how many parent dirs to symlink back */
1109 (*ptr++ == '/') ? depth++ : 0;
1114 ct_path_archive(dst, sizeof(dst), buf, &hai->hai_fid);
1116 if (ct_mkdir_p(src)) {
1117 CT_ERROR(errno, "mkdir_p '%s' failed", src);
1118 rcf = rcf ? rcf : -errno;
1121 /* symlink already exists ? */
1122 sz = readlink(src, buf, sizeof(buf));
1123 /* detect truncation */
1124 if (sz == sizeof(buf)) {
1125 rcf = rcf ? rcf : -E2BIG;
1126 CT_ERROR(rcf, "readlink '%s' truncated", src);
1131 if (sz == 0 || strncmp(buf, dst, sz) != 0) {
1132 if (unlink(src) && errno != ENOENT) {
1134 "cannot unlink symlink '%s'",
1136 rcf = rcf ? rcf : -errno;
1139 /* unlink old symlink done */
1140 CT_TRACE("remove old symlink '%s' pointing"
1141 " to '%s'", src, buf);
1143 /* symlink already ok */
1144 CT_TRACE("symlink '%s' already pointing"
1145 " to '%s'", src, dst);
1150 if (symlink(dst, src)) {
1151 CT_ERROR(errno, "cannot symlink '%s' to '%s'",
1153 rcf = rcf ? rcf : -errno;
1156 CT_TRACE("symlink '%s' to '%s' done", src, dst);
1168 if (ct_is_retryable(rc))
1169 hp_flags |= HP_FLAG_RETRY;
1180 rc = ct_fini(&hcp, hai, hp_flags, rcf);
1185 static int ct_restore(const struct hsm_action_item *hai, const long hal_flags)
1187 struct hsm_copyaction_private *hcp = NULL;
1190 char lov_buf[XATTR_SIZE_MAX];
1191 size_t lov_size = sizeof(lov_buf);
1200 /* we fill lustre so:
1201 * source = lustre FID in the backend
1202 * destination = data FID = volatile file
1205 /* build backend file name from released file FID */
1206 ct_path_archive(src, sizeof(src), opt.o_hsm_root, &hai->hai_fid);
1208 rc = llapi_get_mdt_index_by_fid(opt.o_mnt_fd, &hai->hai_fid,
1211 CT_ERROR(rc, "cannot get mdt index "DFID"",
1212 PFID(&hai->hai_fid));
1215 /* restore loads and sets the LOVEA w/o interpreting it to avoid
1216 * dependency on the structure format. */
1217 rc = ct_load_stripe(src, lov_buf, &lov_size);
1219 CT_WARN("cannot get stripe rules for '%s' (%s), use default",
1220 src, strerror(-rc));
1223 open_flags |= O_LOV_DELAY_CREATE;
1227 rc = ct_begin_restore(&hcp, hai, mdt_index, open_flags);
1231 /* get the FID of the volatile file */
1232 rc = llapi_hsm_action_get_dfid(hcp, &dfid);
1234 CT_ERROR(rc, "restoring "DFID
1235 ", cannot get FID of created volatile file",
1236 PFID(&hai->hai_fid));
1240 /* build volatile "file name", for messages */
1241 snprintf(dst, sizeof(dst), "{VOLATILE}="DFID, PFID(&dfid));
1243 CT_TRACE("restoring data from '%s' to '%s'", src, dst);
1245 if (opt.o_dry_run) {
1250 src_fd = open(src, O_RDONLY | O_NOATIME | O_NOFOLLOW);
1253 CT_ERROR(rc, "cannot open '%s' for read", src);
1257 dst_fd = llapi_hsm_action_get_fd(hcp);
1260 CT_ERROR(rc, "cannot open '%s' for write", dst);
1265 /* the layout cannot be allocated through .fid so we have to
1266 * restore a layout */
1267 rc = ct_restore_stripe(src, dst, dst_fd, lov_buf, lov_size);
1269 CT_ERROR(rc, "cannot restore file striping info"
1270 " for '%s' from '%s'", dst, src);
1276 rc = ct_copy_data(hcp, src, dst, src_fd, dst_fd, hai, hal_flags);
1278 CT_ERROR(rc, "cannot copy data from '%s' to '%s'",
1281 if (ct_is_retryable(rc))
1282 hp_flags |= HP_FLAG_RETRY;
1286 CT_TRACE("data restore from '%s' to '%s' done", src, dst);
1289 rc = ct_fini(&hcp, hai, hp_flags, rc);
1291 /* object swaping is done by cdt at copy end, so close of volatile file
1292 * cannot be done before */
1302 static int ct_remove(const struct hsm_action_item *hai, const long hal_flags)
1304 struct hsm_copyaction_private *hcp = NULL;
1305 char dst[PATH_MAX], attr[PATH_MAX + 4];
1308 rc = ct_begin(&hcp, hai);
1312 ct_path_archive(dst, sizeof(dst), opt.o_hsm_root, &hai->hai_fid);
1314 CT_TRACE("removing file '%s'", dst);
1316 if (opt.o_dry_run) {
1324 CT_ERROR(rc, "cannot unlink '%s'", dst);
1329 snprintf(attr, sizeof(attr), "%s.lov", dst);
1333 CT_ERROR(rc, "cannot unlink '%s'", attr);
1336 /* ignore the error when lov file does not exist. */
1344 rc = ct_fini(&hcp, hai, 0, rc);
1349 static int ct_process_item(struct hsm_action_item *hai, const long hal_flags)
1353 if (opt.o_verbose >= LLAPI_MSG_INFO || opt.o_dry_run) {
1354 /* Print the original path */
1355 char path[PATH_MAX];
1356 long long recno = -1;
1359 CT_TRACE(DFID" action %s reclen %d, cookie=%#jx",
1360 PFID(&hai->hai_fid),
1361 hsm_copytool_action2name(hai->hai_action),
1362 hai->hai_len, (uintmax_t)hai->hai_cookie);
1363 rc = llapi_fid2path_at(opt.o_mnt_fd, &hai->hai_fid, path,
1364 sizeof(path), &recno, &linkno);
1366 CT_ERROR(rc, "cannot get path of "DFID,
1367 PFID(&hai->hai_fid));
1369 CT_TRACE("processing file '%s'", path);
1372 switch (hai->hai_action) {
1373 /* set err_major, minor inside these functions */
1375 rc = ct_archive(hai, hal_flags);
1378 rc = ct_restore(hai, hal_flags);
1381 rc = ct_remove(hai, hal_flags);
1384 CT_TRACE("cancel not implemented for file system '%s'",
1386 /* Don't report progress to coordinator for this cookie:
1387 * the copy function will get ECANCELED when reporting
1394 CT_ERROR(rc, "unknown action %d, on '%s'", hai->hai_action,
1397 ct_fini(NULL, hai, 0, rc);
1405 struct hsm_action_item *hai;
1408 static void *ct_thread(void *data)
1410 struct ct_th_data *cttd = data;
1413 rc = ct_process_item(cttd->hai, cttd->hal_flags);
1417 pthread_exit((void *)(intptr_t)rc);
1420 static int ct_process_item_async(const struct hsm_action_item *hai,
1423 pthread_attr_t attr;
1425 struct ct_th_data *data;
1428 data = malloc(sizeof(*data));
1432 data->hai = malloc(hai->hai_len);
1433 if (data->hai == NULL) {
1438 memcpy(data->hai, hai, hai->hai_len);
1439 data->hal_flags = hal_flags;
1441 rc = pthread_attr_init(&attr);
1443 CT_ERROR(rc, "pthread_attr_init failed for '%s' service",
1450 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1452 rc = pthread_create(&thread, &attr, ct_thread, data);
1454 CT_ERROR(rc, "cannot create thread for '%s' service",
1457 pthread_attr_destroy(&attr);
1461 static int ct_import_one(const char *src, const char *dst)
1463 char newarc[PATH_MAX];
1468 CT_TRACE("importing '%s' from '%s'", dst, src);
1470 if (stat(src, &st) < 0) {
1472 CT_ERROR(rc, "cannot stat '%s'", src);
1479 rc = llapi_hsm_import(dst,
1480 opt.o_archive_id_used ?
1481 opt.o_archive_id[0] : 0,
1482 &st, 0, 0, 0, 0, NULL, &fid);
1484 CT_ERROR(rc, "cannot import '%s' from '%s'", dst, src);
1488 ct_path_archive(newarc, sizeof(newarc), opt.o_hsm_root, &fid);
1490 rc = ct_mkdir_p(newarc);
1492 CT_ERROR(rc, "mkdir_p '%s' failed", newarc);
1498 /* Lots of choices now: mv, ln, ln -s ? */
1499 rc = link(src, newarc); /* hardlink */
1502 CT_ERROR(rc, "cannot link '%s' to '%s'", newarc, src);
1506 CT_TRACE("imported '%s' from '%s'=='%s'", dst, newarc, src);
1511 static char *path_concat(const char *dirname, const char *basename)
1516 rc = asprintf(&result, "%s/%s", dirname, basename);
1523 static int ct_import_fid(const struct lu_fid *import_fid)
1525 char fid_path[PATH_MAX];
1528 ct_path_lustre(fid_path, sizeof(fid_path), opt.o_mnt, import_fid);
1529 rc = access(fid_path, F_OK);
1530 if (rc == 0 || errno != ENOENT) {
1531 rc = (errno == 0) ? -EEXIST : -errno;
1532 CT_ERROR(rc, "cannot import '"DFID"'", PFID(import_fid));
1536 ct_path_archive(fid_path, sizeof(fid_path), opt.o_hsm_root,
1539 CT_TRACE("Resolving "DFID" to %s", PFID(import_fid), fid_path);
1541 return ct_import_one(fid_path, opt.o_dst);
1544 static int ct_import_recurse(const char *relpath)
1548 char *srcpath, *newpath;
1549 struct lu_fid import_fid;
1552 if (relpath == NULL)
1555 /* Is relpath a FID? */
1556 rc = llapi_fid_parse(relpath, &import_fid, NULL);
1558 return ct_import_fid(&import_fid);
1560 srcpath = path_concat(opt.o_hsm_root, relpath);
1561 if (srcpath == NULL) {
1566 dir = opendir(srcpath);
1568 /* Not a dir, or error */
1569 if (errno == ENOTDIR) {
1570 /* Single regular file case, treat o_dst as absolute
1572 rc = ct_import_one(srcpath, opt.o_dst);
1575 CT_ERROR(rc, "cannot opendir '%s'", srcpath);
1583 while ((ent = readdir(dir)) != NULL) {
1584 if (!strcmp(ent->d_name, ".") ||
1585 !strcmp(ent->d_name, ".."))
1588 /* New relative path */
1589 newpath = path_concat(relpath, ent->d_name);
1590 if (newpath == NULL) {
1596 if (ent->d_type == DT_DIR) {
1597 rc = ct_import_recurse(newpath);
1602 sprintf(src, "%s/%s", opt.o_hsm_root, newpath);
1603 sprintf(dst, "%s/%s", opt.o_dst, newpath);
1604 /* Make the target dir in the Lustre fs */
1605 rc = ct_mkdir_p(dst);
1607 /* Import the file */
1608 rc = ct_import_one(src, dst);
1610 CT_ERROR(rc, "ct_mkdir_p '%s' failed", dst);
1616 CT_ERROR(rc, "cannot import '%s'", newpath);
1617 if (err_major && opt.o_abort_on_error) {
1631 static int ct_rebind_one(const struct lu_fid *old_fid,
1632 const struct lu_fid *new_fid)
1638 CT_TRACE("rebind "DFID" to "DFID, PFID(old_fid), PFID(new_fid));
1640 ct_path_archive(src, sizeof(src), opt.o_hsm_root, old_fid);
1641 ct_path_archive(dst, sizeof(dst), opt.o_hsm_root, new_fid);
1643 if (!opt.o_dry_run) {
1644 char src_attr[PATH_MAX + 4];
1645 char dst_attr[PATH_MAX + 4];
1648 if (rename(src, dst)) {
1650 CT_ERROR(rc, "cannot rename '%s' to '%s'", src, dst);
1653 /* rename lov file */
1654 snprintf(src_attr, sizeof(src_attr), "%s.lov", src);
1655 snprintf(dst_attr, sizeof(dst_attr), "%s.lov", dst);
1656 if (rename(src_attr, dst_attr))
1657 CT_ERROR(errno, "cannot rename '%s' to '%s'",
1658 src_attr, dst_attr);
1664 static bool fid_is_file(struct lu_fid *fid)
1666 return fid_is_norm(fid) || fid_is_igif(fid);
1669 static bool should_ignore_line(const char *line)
1673 for (i = 0; line[i] != '\0'; i++) {
1674 if (isspace(line[i]))
1676 else if (line[i] == '#')
1685 static int ct_rebind_list(const char *list)
1691 size_t line_size = 0;
1692 unsigned int nl = 0;
1693 unsigned int ok = 0;
1695 filp = fopen(list, "r");
1698 CT_ERROR(rc, "cannot open '%s'", list);
1702 /* each line consists of 2 FID */
1703 while ((r = getline(&line, &line_size, filp)) != -1) {
1704 struct lu_fid old_fid;
1705 struct lu_fid new_fid;
1708 /* Ignore empty and commented out ('#...') lines. */
1709 if (should_ignore_line(line))
1714 rc = llapi_fid_parse(line, &old_fid, &next_fid);
1717 rc = llapi_fid_parse(next_fid, &new_fid, NULL);
1720 if (!fid_is_file(&old_fid) || !fid_is_file(&new_fid))
1723 error: CT_ERROR(rc, "%s:%u: two FIDs expected in '%s'",
1729 if (ct_rebind_one(&old_fid, &new_fid))
1740 /* return 0 if all rebinds were successful */
1741 CT_TRACE("%u lines read from '%s', %u rebind successful", nl, list, ok);
1743 return ok == nl ? 0 : -1;
1746 static int ct_rebind(void)
1751 struct lu_fid old_fid;
1752 struct lu_fid new_fid;
1754 rc = llapi_fid_parse(opt.o_src, &old_fid, NULL);
1755 if (!rc && !fid_is_file(&old_fid))
1758 CT_ERROR(rc, "invalid source FID '%s'", opt.o_src);
1762 rc = llapi_fid_parse(opt.o_dst, &new_fid, NULL);
1763 if (!rc && !fid_is_file(&new_fid))
1766 CT_ERROR(rc, "invalid destination FID '%s'", opt.o_dst);
1770 rc = ct_rebind_one(&old_fid, &new_fid);
1775 /* o_src is a list file */
1776 rc = ct_rebind_list(opt.o_src);
1781 static int ct_dir_level_max(const char *dirpath, __u16 *sub_seqmax)
1790 dir = opendir(dirpath);
1793 CT_ERROR(rc, "cannot open directory '%s'", opt.o_hsm_root);
1801 /* end of directory.
1802 * rc is 0 and seqmax contains the max value. */
1805 CT_ERROR(rc, "cannot readdir '%s'", dirpath);
1809 if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
1812 if (sscanf(ent->d_name, "%hx", &sub_seq) != 1) {
1813 CT_TRACE("'%s' has an unexpected dirname format, "
1814 "skip entry", ent->d_name);
1817 if (sub_seq > *sub_seqmax)
1818 *sub_seqmax = sub_seq;
1825 static int ct_max_sequence(void)
1828 char path[PATH_MAX];
1832 snprintf(path, sizeof(path), "%s", opt.o_hsm_root);
1833 /* FID sequence is stored in top-level directory names:
1834 * hsm_root/16bits (high weight)/16 bits/16 bits/16 bits (low weight).
1836 for (i = 0; i < 4; i++) {
1839 rc = ct_dir_level_max(path, &subseq);
1842 seq |= ((__u64)subseq << ((3 - i) * 16));
1843 path_len = strlen(path);
1844 rc = snprintf(path + path_len, sizeof(path) - path_len,
1846 if (rc >= (sizeof(path) - path_len))
1848 path[sizeof(path) - 1] = '\0';
1851 printf("max_sequence: %#jx\n", (uintmax_t)seq);
1856 static void handler(int signal)
1858 psignal(signal, "exiting");
1859 /* If we don't clean up upon interrupt, umount thinks there's a ref
1860 * and doesn't remove us from mtab (EINPROGRESS). The lustre client
1861 * does successfully unmount and the mount is actually gone, but the
1862 * mtab entry remains. So this just makes mtab happier. */
1863 llapi_hsm_copytool_unregister(&ctdata);
1865 /* Also remove fifo upon signal as during normal/error exit */
1866 if (opt.o_event_fifo != NULL)
1867 llapi_hsm_unregister_event_fifo(opt.o_event_fifo);
1871 /* Daemon waits for messages from the kernel; run it in the background. */
1872 static int ct_run(void)
1874 struct sigaction cleanup_sigaction;
1877 if (opt.o_daemonize) {
1881 CT_ERROR(rc, "cannot daemonize");
1886 if (opt.o_pid_file != NULL) {
1887 pid_file_fd = create_pid_file(opt.o_pid_file);
1888 if (pid_file_fd < 0) {
1890 CT_ERROR(rc, "cannot create PID file");
1895 setbuf(stdout, NULL);
1897 if (opt.o_event_fifo != NULL) {
1898 rc = llapi_hsm_register_event_fifo(opt.o_event_fifo);
1900 CT_ERROR(rc, "failed to register event fifo");
1903 llapi_error_callback_set(llapi_hsm_log_error);
1906 rc = llapi_hsm_copytool_register(&ctdata, opt.o_mnt,
1907 opt.o_archive_id_used,
1908 opt.o_archive_id, 0);
1910 CT_ERROR(rc, "cannot start copytool interface");
1914 memset(&cleanup_sigaction, 0, sizeof(cleanup_sigaction));
1915 cleanup_sigaction.sa_handler = handler;
1916 sigemptyset(&cleanup_sigaction.sa_mask);
1917 sigaction(SIGINT, &cleanup_sigaction, NULL);
1918 sigaction(SIGTERM, &cleanup_sigaction, NULL);
1921 struct hsm_action_list *hal;
1922 struct hsm_action_item *hai;
1926 CT_TRACE("waiting for message from kernel");
1928 rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize);
1929 if (rc == -ESHUTDOWN) {
1930 CT_TRACE("shutting down");
1932 } else if (rc < 0) {
1933 CT_WARN("cannot receive action list: %s",
1936 if (opt.o_abort_on_error)
1942 CT_TRACE("copytool fs=%s archive#=%d item_count=%d",
1943 hal->hal_fsname, hal->hal_archive_id, hal->hal_count);
1945 if (strcmp(hal->hal_fsname, fs_name) != 0) {
1947 CT_ERROR(rc, "'%s' invalid fs name, expecting: %s",
1948 hal->hal_fsname, fs_name);
1950 if (opt.o_abort_on_error)
1956 hai = hai_first(hal);
1957 while (++i <= hal->hal_count) {
1958 if ((char *)hai - (char *)hal > msgsize) {
1961 "'%s' item %d past end of message!",
1966 rc = ct_process_item_async(hai, hal->hal_flags);
1968 CT_ERROR(rc, "'%s' item %d process",
1970 if (opt.o_abort_on_error && err_major)
1972 hai = hai_next(hai);
1975 if (opt.o_abort_on_error && err_major)
1979 llapi_hsm_copytool_unregister(&ctdata);
1980 if (opt.o_event_fifo != NULL)
1981 llapi_hsm_unregister_event_fifo(opt.o_event_fifo);
1986 static int ct_setup(void)
1990 /* set llapi message level */
1991 llapi_msg_set_level(opt.o_verbose);
1993 arc_fd = open(opt.o_hsm_root, O_RDONLY);
1996 CT_ERROR(rc, "cannot open archive at '%s'", opt.o_hsm_root);
2000 rc = llapi_search_fsname(opt.o_mnt, fs_name);
2002 CT_ERROR(rc, "cannot find a Lustre filesystem mounted at '%s'",
2007 opt.o_mnt_fd = open(opt.o_mnt, O_RDONLY);
2008 if (opt.o_mnt_fd < 0) {
2010 CT_ERROR(rc, "cannot open mount point at '%s'",
2018 static int ct_cleanup(void)
2022 if (opt.o_mnt_fd >= 0) {
2023 rc = close(opt.o_mnt_fd);
2026 CT_ERROR(rc, "cannot close mount point");
2035 CT_ERROR(rc, "cannot close archive root directory");
2040 if (opt.o_archive_id_cnt > 0) {
2041 free(opt.o_archive_id);
2042 opt.o_archive_id = NULL;
2043 opt.o_archive_id_cnt = 0;
2049 int main(int argc, char **argv)
2053 snprintf(cmd_name, sizeof(cmd_name), "%s", basename(argv[0]));
2054 rc = ct_parseopts(argc, argv);
2056 CT_WARN("try '%s --help' for more information", cmd_name);
2064 switch (opt.o_action) {
2066 rc = ct_import_recurse(opt.o_src);
2072 rc = ct_max_sequence();
2079 if (opt.o_action != CA_MAXSEQ)
2080 CT_TRACE("process finished, errs: %d major, %d minor,"
2081 " rc=%d (%s)", err_major, err_minor, rc,