do_facet $SINGLEAGT $LFS pcc pin -i $HSM_ARCHIVE_NUMBER $file ||
error "failed to pcc pin $file"
do_facet $SINGLEAGT getfattr $file -d -m $xattrname
- xattrvalue=$(do_facet $SINGLEAGT getfattr $file -d -m $xattrname \
- --only-values)
+ xattrvalue=$(do_facet $SINGLEAGT getfattr $file -d -m $xattrname --only-values)
[[ "$xattrvalue" =~ "hsm: $HSM_ARCHIVE_NUMBER" ]] ||
error "incorrect xattr $xattrname=$xattrvalue"
do_facet $SINGLEAGT $LFS pcc pin -i 100 $file ||
error "failed to pcc pin $file"
do_facet $SINGLEAGT getfattr $file -d -m $xattrname
- xattrvalue=$(do_facet $SINGLEAGT getfattr $file -d -m $xattrname \
- --only-values)
+ xattrvalue=$(do_facet $SINGLEAGT getfattr $file -d -m $xattrname --only-values)
[[ "$xattrvalue" =~ "hsm: $HSM_ARCHIVE_NUMBER" &&
"$xattrvalue" =~ "hsm: 100" ]] ||
error "incorrect xattr $xattrname=$xattrvalue"
do_facet $SINGLEAGT $LFS pcc unpin -i 100 $file ||
error "failed to pcc unpin $file"
do_facet $SINGLEAGT getfattr $file -d -m $xattrname
- xattrvalue=$(do_facet $SINGLEAGT getfattr $file -d -m $xattrname \
- --only-values)
+ xattrvalue=$(do_facet $SINGLEAGT getfattr $file -d -m $xattrname --only-values)
[[ "$xattrvalue" =~ "hsm: $HSM_ARCHIVE_NUMBER" ]] ||
error "incorrect xattr $xattrname=$xattrvalue"
do_facet $SINGLEAGT $LFS pcc unpin -i $HSM_ARCHIVE_NUMBER $file ||
error "failed to pcc unpin $file"
do_facet $SINGLEAGT getfattr $file -d -m $xattrname
- xattrvalue=$(do_facet $SINGLEAGT getfattr $file -d -m $xattrname \
- --only-values)
+ xattrvalue=$(do_facet $SINGLEAGT getfattr $file -d -m $xattrname --only-values)
[[ -z "$xattrvalue" ]] ||
error "incorrect xattr $xattrname=$xattrvalue"
local file=$DIR/$tfile
local xattrname="trusted.pin"
local xattrvalue
- local fid
(( $MDS1_VERSION >= $(version_code 2.14.0.38) )) ||
skip "Need server version at least 2.14.0.38"
}
run_test 204b "PCC pin/unpin without attach ID specified"
+test_204c() {
+ local loopfile="$TMP/$tfile"
+ local mntpt="/mnt/pcc.$tdir"
+ local hsm_root="$mntpt/$tdir"
+ local file
+ local fid
+ local xattrname="trusted.pin"
+
+ (( $MDS1_VERSION >= $(version_code 2.14.0.38) )) ||
+ skip "Need server version at least 2.14.0.38"
+
+ setup_loopdev $SINGLEAGT $loopfile $mntpt 14
+ do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed"
+ setup_pcc_mapping $SINGLEAGT \
+ "fname={*.dat}\ roid=$HSM_ARCHIVE_NUMBER\ pccro=1"
+
+ # attach --pin with archive id
+ file=$DIR/$tfile.1
+ do_facet $SINGLEAGT touch $file || error "failed to create $file"
+
+ do_facet $SINGLEAGT \
+ $LFS pcc attach -i $HSM_ARCHIVE_NUMBER --pin $file ||
+ error "failed to attach $file with --pin option"
+ check_lpcc_state $file "readonly"
+ xattrvalue=$(do_facet $SINGLEAGT getfattr $file -n $xattrname --only-values)
+ [[ "$xattrvalue" =~ "hsm: $HSM_ARCHIVE_NUMBER" ]] ||
+ error "incorrect xattr $xattrname=$xattrvalue"
+
+ # attach_fid --pin without archive id
+ file=$DIR/$tfile.2
+ do_facet $SINGLEAGT touch $file || error "failed to create $file"
+ # remove [] for it causes chaos later
+ fid=$(path2fid $file)
+
+ do_facet $SINGLEAGT \
+ $LFS pcc attach_fid -m $MOUNT --pin $fid ||
+ error "failed to attach fid $fid with --pin option"
+ check_lpcc_state $file "readonly"
+ xattrvalue=$(do_facet $SINGLEAGT getfattr $file -n $xattrname --only-values)
+ [[ "$xattrvalue" =~ "hsm: $HSM_ARCHIVE_NUMBER" ]] ||
+ error "incorrect xattr $xattrname=$xattrvalue"
+}
+run_test 204c "attach/attach_fid with --pin option"
+
complete $SECONDS
check_and_cleanup_lustre
exit_status
*/
command_t pcc_cmdlist[] = {
{ .pc_name = "attach", .pc_func = lfs_pcc_attach,
- .pc_help = "Attach given files to the Persistent Client Cache.\n"
- "usage: lfs pcc attach [--id|-i ID] [--readonly|-r] [--write|-w] <file> ...\n"
+ .pc_help = "Copy given files to PCC, the local cache storage.\n"
+ "usage: lfs pcc attach [--id|-i ID] [--readonly|-r] [--write|-w] [-p|--pin] <file> ...\n"
"\t-i: archive ID for PCC\n"
"\t-r: readonly attach\n"
- "\t-w: writeable attach\n" },
+ "\t-w: writeable attach\n"
+ "\t-p: pin and attach the file\n" },
{ .pc_name = "attach_fid", .pc_func = lfs_pcc_attach_fid,
- .pc_help = "Attach given files into PCC by FID(s).\n"
- "usage: lfs pcc attach_fid [--id|-i ID] {--mnt|-m MOUNTPATH} [--readonly|-r] [--write|-w] <FID> ...\n"
+ .pc_help = "Copy given files to PCC by FID(s), the local cache storage.\n"
+ "usage: lfs pcc attach_fid [--id|-i ID] {--mnt|-m MOUNTPATH} [--readonly|-r] [--write|-w] [-p|--pin] <FID> ...\n"
"\t-i: archive ID for PCC\n"
"\t-m: Lustre mount point\n"
"\t-r: readonly attach\n"
- "\t-w: writeable attach\n" },
+ "\t-w: writeable attach\n"
+ "\t-p: pin and attach the file\n" },
{ .pc_name = "state", .pc_func = lfs_pcc_state,
.pc_help = "Display the PCC state for given files.\n"
"usage: lfs pcc state <FILE> ...\n" },
{ .val = 'i', .name = "id", .has_arg = required_argument },
{ .val = 'r', .name = "readonly", .has_arg = no_argument },
{ .val = 'w', .name = "write", .has_arg = no_argument },
+ { .val = 'p', .name = "pin", .has_arg = no_argument },
{ .name = NULL } };
int c;
int rc = 0;
char *end;
char fullpath[PATH_MAX];
enum lu_pcc_type type = LU_PCC_READONLY;
+ bool pin = false;
optind = 0;
- while ((c = getopt_long(argc, argv, "i:rw",
+ while ((c = getopt_long(argc, argv, "i:prw",
long_opts, NULL)) != -1) {
switch (c) {
case 'i':
case 'w':
type = LU_PCC_READWRITE;
break;
+ case 'p':
+ pin = true;
+ break;
case '?':
return CMD_HELP;
default:
continue;
}
+ if (pin) {
+ if (attach_id == 0) {
+ rc2 = llapi_pcc_backend_id_get(fullpath, type,
+ &attach_id);
+ if (rc2 < 0) {
+ fprintf(stderr,
+ "%s: failed to get archive id for '%s': %s\n",
+ argv[0], path, strerror(-rc2));
+ if (rc == 0)
+ rc = rc2;
+ continue;
+ }
+ }
+ rc2 = llapi_pcc_pin_file(fullpath, attach_id);
+ if (rc2 < 0) {
+ fprintf(stderr, "%s: cannot pin '%s': %s\n",
+ argv[0], path, strerror(-rc2));
+ if (rc == 0)
+ rc = rc2;
+ }
+ }
+
rc2 = llapi_pcc_attach(fullpath, attach_id, type);
if (rc2 < 0) {
fprintf(stderr,
{ .val = 'r', .name = "readonly", .has_arg = no_argument },
{ .val = 'w', .name = "write", .has_arg = no_argument },
{ .val = 'm', .name = "mnt", .has_arg = required_argument },
+ { .val = 'p', .name = "pin", .has_arg = no_argument },
{ .name = NULL } };
- char short_opts[] = "i:m:rw";
- int c;
- int rc = 0;
- __u32 attach_id = 0;
- char *end;
- const char *mntpath = NULL;
- const char *fidstr;
- enum lu_pcc_type type = LU_PCC_READONLY;
+ char short_opts[] = "i:m:prw";
+ int c;
+ int rc = 0;
+ __u32 attach_id = 0;
+ char *end;
+ const char *mntpath = NULL;
+ const char *fidstr;
+ enum lu_pcc_type type = LU_PCC_READONLY;
+ bool pin = false;
+ struct lu_fid fid;
optind = 0;
while ((c = getopt_long(argc, argv, short_opts,
case 'm':
mntpath = optarg;
break;
+ case 'p':
+ pin = true;
+ break;
case '?':
return CMD_HELP;
default:
return CMD_HELP;
}
+ if (pin && attach_id == 0) {
+ rc = llapi_pcc_backend_id_get(mntpath, type,
+ &attach_id);
+ if (rc < 0) {
+ fprintf(stderr,
+ "%s: failed to get archive id for "DFID" on '%s': %s\n",
+ argv[0], PFID(&fid), mntpath,
+ strerror(-rc));
+ return rc;
+ }
+ }
+
while (optind < argc) {
int rc2;
fidstr = argv[optind++];
- rc2 = llapi_pcc_attach_fid_str(mntpath, fidstr,
- attach_id, type);
+ rc2 = llapi_fid_parse(fidstr, &fid, NULL);
+ if (rc2) {
+ fprintf(stderr, "%s: invalid fid string: %s\n",
+ argv[0], strerror(-rc2));
+ rc = rc ? rc : rc2;
+ continue;
+ }
+
+ if (pin) {
+ rc2 = llapi_pcc_pin_fid(mntpath, &fid, attach_id);
+ if (rc2) {
+ fprintf(stderr, "%s: cannot pin fid '%s' on '%s': %s\n",
+ argv[0], fidstr, mntpath,
+ strerror(-rc2));
+ rc = rc ? rc : rc2;
+ continue;
+ }
+ }
+
+ rc2 = llapi_pcc_attach_fid(mntpath, &fid, attach_id, type);
if (rc2 < 0) {
fprintf(stderr,
"%s: cannot attach '%s' on '%s' to PCC with attach ID '%u': %s\n",