#include <libcfs/util/string.h>
#include <linux/lustre/lustre_fid.h>
#include <lustre/lustreapi.h>
+#include "pid_file.h"
/* Progress reporting period */
#define REPORT_INTERVAL_DEFAULT 30
char *o_hsm_root;
char *o_src; /* for import, or rebind */
char *o_dst; /* for import, or rebind */
+ char *o_pid_file;
};
/* everything else is zeroed */
static char cmd_name[PATH_MAX];
static char fs_name[MAX_OBD_NAME + 1];
+static int pid_file_fd = -1;
static struct hsm_copytool_private *ctdata;
" -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, --pid-file=PATH Lock and write PID to PATH\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"
.flag = &opt.o_copy_xattrs },
{ .val = 0, .name = "no_xattr", .has_arg = no_argument,
.flag = &opt.o_copy_xattrs },
+ { .val = 'P', .name = "pid-file", .has_arg = required_argument },
{ .val = 'p', .name = "hsm-root", .has_arg = required_argument },
{ .val = 'p', .name = "hsm_root", .has_arg = required_argument },
{ .val = 'q', .name = "quiet", .has_arg = no_argument },
.has_arg = required_argument },
{ .val = 'v', .name = "verbose", .has_arg = no_argument },
{ .name = NULL } };
+
unsigned long long value;
unsigned long long unit;
bool all_id = false;
if (opt.o_archive_id == NULL)
return -ENOMEM;
repeat:
- while ((c = getopt_long(argc, argv, "A:b:c:f:hiMp:qru:v",
+ while ((c = getopt_long(argc, argv, "A:b:c:f:hiMp:P:qru:v",
long_opts, NULL)) != -1) {
switch (c) {
case 'A': {
opt.o_archive_id_cnt = 0;
opt.o_archive_id_used = 0;
all_id = true;
- CT_WARN("archive-id = 0 is found, any backend"
- "will be served\n");
+ CT_WARN("archive-id = 0 is found, any backend will be served\n");
goto repeat;
}
case 'M':
opt.o_action = CA_MAXSEQ;
break;
+ case 'P':
+ opt.o_pid_file = optarg;
+ break;
case 'p':
opt.o_hsm_root = optarg;
break;
static int ct_path_lustre(char *buf, int sz, const char *mnt,
const struct lu_fid *fid)
{
- return snprintf(buf, sz, "%s/%s/fid/"DFID_NOBRACE, mnt,
- dot_lustre_name, PFID(fid));
+ return scnprintf(buf, sz, "%s/%s/fid/"DFID_NOBRACE, mnt,
+ dot_lustre_name, PFID(fid));
}
static int ct_path_archive(char *buf, int sz, const char *archive_dir,
const struct lu_fid *fid)
{
- return snprintf(buf, sz, "%s/%04x/%04x/%04x/%04x/%04x/%04x/"
- DFID_NOBRACE, archive_dir,
- (fid)->f_oid & 0xFFFF,
- (fid)->f_oid >> 16 & 0xFFFF,
- (unsigned int)((fid)->f_seq & 0xFFFF),
- (unsigned int)((fid)->f_seq >> 16 & 0xFFFF),
- (unsigned int)((fid)->f_seq >> 32 & 0xFFFF),
- (unsigned int)((fid)->f_seq >> 48 & 0xFFFF),
- PFID(fid));
+ return scnprintf(buf, sz, "%s/%04x/%04x/%04x/%04x/%04x/%04x/"
+ DFID_NOBRACE, archive_dir,
+ (fid)->f_oid & 0xFFFF,
+ (fid)->f_oid >> 16 & 0xFFFF,
+ (unsigned int)((fid)->f_seq & 0xFFFF),
+ (unsigned int)((fid)->f_seq >> 16 & 0xFFFF),
+ (unsigned int)((fid)->f_seq >> 32 & 0xFFFF),
+ (unsigned int)((fid)->f_seq >> 48 & 0xFFFF),
+ PFID(fid));
}
static bool ct_is_retryable(int err)
int depth = 0;
ssize_t sz;
- sprintf(buf, DFID, PFID(&hai->hai_fid));
sprintf(src, "%s/shadow/", opt.o_hsm_root);
ptr = opt.o_hsm_root;
while (*ptr)
(*ptr++ == '/') ? depth-- : 0;
- rc = llapi_fid2path(opt.o_mnt, buf, src + strlen(src),
- sizeof(src) - strlen(src), &recno, &linkno);
+ rc = llapi_fid2path_at(opt.o_mnt_fd, &hai->hai_fid,
+ src + strlen(src),
+ sizeof(src) - strlen(src),
+ &recno, &linkno);
if (rc < 0) {
- CT_ERROR(rc, "cannot get FID of '%s'", buf);
+ CT_ERROR(rc, "cannot get FID of "DFID,
+ PFID(&hai->hai_fid));
rcf = rcf ? rcf : rc;
goto fini_minor;
}
if (opt.o_verbose >= LLAPI_MSG_INFO || opt.o_dry_run) {
/* Print the original path */
- char fid[128];
char path[PATH_MAX];
long long recno = -1;
int linkno = 0;
- sprintf(fid, DFID, PFID(&hai->hai_fid));
- CT_TRACE("'%s' action %s reclen %d, cookie=%#jx",
- fid, hsm_copytool_action2name(hai->hai_action),
+ CT_TRACE(DFID" action %s reclen %d, cookie=%#jx",
+ PFID(&hai->hai_fid),
+ hsm_copytool_action2name(hai->hai_action),
hai->hai_len, (uintmax_t)hai->hai_cookie);
- rc = llapi_fid2path(opt.o_mnt, fid, path,
- sizeof(path), &recno, &linkno);
+ rc = llapi_fid2path_at(opt.o_mnt_fd, &hai->hai_fid, path,
+ sizeof(path), &recno, &linkno);
if (rc < 0)
- CT_ERROR(rc, "cannot get path of FID %s", fid);
+ CT_ERROR(rc, "cannot get path of "DFID,
+ PFID(&hai->hai_fid));
else
CT_TRACE("processing file '%s'", path);
}
return 0;
rc = llapi_hsm_import(dst,
- opt.o_archive_id_used ?
- opt.o_archive_id[0] : 0,
- &st, 0, 0, 0, 0, NULL, &fid);
+ opt.o_archive_id_used ? opt.o_archive_id[0] : 0,
+ &st,
+ 0 /* default stripe_size */,
+ -1 /* default stripe offset */,
+ 0 /* default stripe count */,
+ 0 /* stripe pattern (will be RAID0+RELEASED) */,
+ NULL /* pool_name */,
+ &fid);
if (rc < 0) {
CT_ERROR(rc, "cannot import '%s' from '%s'", dst, src);
return rc;
}
}
+ if (opt.o_pid_file != NULL) {
+ pid_file_fd = create_pid_file(opt.o_pid_file);
+ if (pid_file_fd < 0) {
+ rc = -errno;
+ CT_ERROR(rc, "cannot create PID file");
+ return rc;
+ }
+ }
+
setbuf(stdout, NULL);
if (opt.o_event_fifo != NULL) {