.IR FILE .
If
.I ID
-is not specified, then use the first archive attached to the mounted
+is not specified, use the first archive attached to the mounted
filesystem by default.
.TP
.BR --mnt | -m
The ARCHIVE
.I ID
to be pinned or un-pinned.
+If
+.I ID
+is not specified, use the first archive attached to the mounted
+filesystem by default.
.SH EXAMPLES
.TP
int llapi_pcc_clear(const char *mntpath, enum lu_pcc_cleanup_flags flags);
int llapi_pcc_pin_file(const char *path, __u32 id);
int llapi_pcc_unpin_file(const char *path, __u32 id);
-
+int llapi_pcc_backend_id_get(const char *path, enum lu_pcc_type type,
+ __u32 *id);
/** @} llapi */
/* llapi_layout user interface */
}
run_test 203 "Verify attach/hit bytes statistics data"
-test_204() {
+test_204a() {
local loopfile="$TMP/$tfile"
local mntpt="/mnt/pcc.$tdir"
local hsm_root="$mntpt/$tdir"
do_facet $SINGLEAGT cat $file
check_lpcc_state $file "readonly"
}
-run_test 204 "pin/unpin pcc flag"
+run_test 204a "pin/unpin pcc flag"
+
+test_204b() {
+ local loopfile="$TMP/$tfile"
+ local mntpt="/mnt/pcc.$tdir"
+ local hsm_root="$mntpt/$tdir"
+ local file=$DIR/$tfile
+ local xattrname="trusted.pin"
+ local xattrvalue
+ local fid
+
+ $LCTL get_param -n mdc.*.connect_flags | grep -q pcc_ro ||
+ skip "Server does not support PCC-RO"
+
+ (( $MDS1_VERSION >= $(version_code 2.15.61) )) ||
+ skip "Need server version at least 2.15.61"
+
+ do_facet $SINGLEAGT echo -n attach_id_not_specified > $file ||
+ error "dd write $file failed"
+ do_facet $SINGLEAGT $LFS pcc pin $file &&
+ error "Pin should fail for a client without any PCC backend"
+
+ setup_loopdev $SINGLEAGT $loopfile $mntpt 60
+ do_facet $SINGLEAGT mkdir $hsm_root || error "mkdir $hsm_root failed"
+ setup_pcc_mapping $SINGLEAGT \
+ "projid={100}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1"
+
+ do_facet $SINGLEAGT $LFS pcc pin $file || error "failed to pin $file"
+ do_facet $SINGLEAGT getfattr $file -n $xattrname
+ xattrvalue=$(do_facet $SINGLEAGT getfattr $file -n $xattrname --only-values)
+ [[ "$xattrvalue" =~ "hsm: $HSM_ARCHIVE_NUMBER" ]] ||
+ error "incorrect xattr $xattrname=$xattrvalue"
+
+ do_facet $SINGLEAGT $LFS pcc unpin $file || error "failed to PCC unpin $file"
+ do_facet $SINGLEAGT getfattr $file -n $xattrname
+ xattrvalue=$(do_facet $SINGLEAGT getfattr $file -n $xattrname --only-values)
+ [[ -z "$xattrvalue" ]] || error "incorrect xattr $xattrname=$xattrvalue"
+}
+run_test 204b "PCC pin/unpin without attach ID specified"
complete_test $SECONDS
check_and_cleanup_lustre
}
/* check parameters */
- if (id == 0) {
- fprintf(stderr, "%s: must specify -i|--id option\n",
- argv[0]);
- return CMD_HELP;
- }
if (argc <= 1) {
fprintf(stderr, "%s: must specify one or more file names\n",
argv[0]);
continue;
}
+ if (id == 0) {
+ rc2 = llapi_pcc_backend_id_get(fullpath,
+ LU_PCC_READONLY, &id);
+ if (rc2 < 0) {
+ fprintf(stderr,
+ "%s: failed to get id for '%s': %s\n",
+ argv[0], path, strerror(-rc2));
+ if (rc == 0)
+ rc = rc2;
+ continue;
+ }
+ }
+
rc2 = llapi_pcc_pin_file(fullpath, id);
if (rc2 < 0) {
fprintf(stderr, "%s: cannot pin '%s' for PCC: %s\n",
}
}
/* check parameters */
- if (id == 0) {
- fprintf(stderr, "%s: must specify -i|--id option\n",
- argv[0]);
- return CMD_HELP;
- }
if (argc <= 1) {
fprintf(stderr, "%s: must specify one or more file names\n",
argv[0]);
continue;
}
+ if (id == 0) {
+ rc2 = llapi_pcc_backend_id_get(fullpath,
+ LU_PCC_READONLY, &id);
+ if (rc2 < 0) {
+ fprintf(stderr,
+ "%s: failed to get id for '%s': %s\n",
+ argv[0], path, strerror(-rc2));
+ if (rc == 0)
+ rc = rc2;
+ continue;
+ }
+ }
+
rc2 = llapi_pcc_unpin_file(fullpath, id);
if (rc2 < 0) {
fprintf(stderr, "%s: cannot unpin '%s' for PCC: %s\n",
enum pcc_cmd_t {
PCC_CMD_DEL,
PCC_CMD_CLEAR,
+ PCC_CMD_BACKEND_SELECT,
};
struct pcc_cmd_handler {
rc = ret;
}
+out_free:
/* Not found the given PCC backend on the client. */
- if (pch->pch_iter_cont && pch->pch_cmd == PCC_CMD_DEL)
+ if (pch->pch_iter_cont && (pch->pch_cmd == PCC_CMD_DEL ||
+ pch->pch_cmd == PCC_CMD_BACKEND_SELECT))
rc = -ENOENT;
-out_free:
if (tree)
cYAML_free_tree(tree);
cfs_free_param_data(&path);
return llapi_pcc_yaml_cb_helper(&pch);
}
+static int llapi_pcc_yaml_backend_get(struct cYAML *node,
+ struct pcc_cmd_handler *pch)
+{
+ struct cYAML *pccid;
+
+ /* TODO: check the flags of PCC backends. */
+ pccid = cYAML_get_object_item(node, pch->pch_type == LU_PCC_READWRITE ?
+ PCC_YAML_RWID : PCC_YAML_ROID);
+ if (!pccid || pccid->cy_valueint == 0)
+ return 0;
+
+ pch->pch_iter_cont = false;
+ pch->pch_id = pccid->cy_valueint;
+ return 0;
+}
+
+int llapi_pcc_backend_id_get(const char *path, enum lu_pcc_type type, __u32 *id)
+{
+ struct pcc_cmd_handler pch;
+ int rc;
+
+ memset(&pch, 0, sizeof(pch));
+ pch.pch_cmd = PCC_CMD_BACKEND_SELECT;
+ pch.pch_iter_cont = true;
+ pch.pch_mntpath = path;
+ pch.pch_type = type;
+ pch.pch_cb = llapi_pcc_yaml_backend_get;
+
+ rc = llapi_pcc_yaml_cb_helper(&pch);
+ if (rc == 0)
+ *id = pch.pch_id;
+
+ return rc;
+}
+
#define PIN_YAML_HSM_STR "hsm"
static int verify_pin_xattr_object(struct cYAML *yaml)