{ LPROC_LL_LISTXATTR, LPROCFS_TYPE_LATENCY, "listxattr" },
{ LPROC_LL_REMOVEXATTR, LPROCFS_TYPE_LATENCY, "removexattr" },
{ LPROC_LL_INODE_PERM, LPROCFS_TYPE_LATENCY, "inode_permission" },
+ { LPROC_LL_PCC_ATTACH, LPROCFS_TYPE_REQS, "pcc_attach" },
+ { LPROC_LL_PCC_DETACH, LPROCFS_TYPE_REQS, "pcc_detach" },
+ { LPROC_LL_PCC_AUTOAT, LPROCFS_TYPE_REQS, "pcc_auto_attach" },
};
void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, long count)
pcci = ll_i2pcci(inode);
if (pcci && pcc_inode_has_layout(pcci))
*cached = true;
+
if (rc) {
CDEBUG(D_CACHE,
"Failed to try PCC-RO attach "DFID", rc = %d\n",
rc = pcc_try_datasets_attach(inode, iot, clt.cl_layout_gen,
LU_PCC_READONLY, cached);
+ if (*cached)
+ ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_AUTOAT, 1);
+
RETURN(rc);
}
{
__pcc_layout_invalidate(ll_i2pcci(inode));
pcc_inode_mapping_reset(inode);
+ ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_DETACH, 1);
}
static inline void pcc_inode_detach_put(struct inode *inode)
pcc_inode_detach_put(inode);
}
pcc_inode_unlock(inode);
-
EXIT;
}
if (rc) {
pcc_inode_remove(inode, *dentry);
dput(*dentry);
+ } else {
+ ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_PCC_ATTACH, 1);
}
out_cred:
revert_creds(old_cred);
RETURN(rc);
}
-static int pcc_layout_rdonly_set(struct inode *inode, __u32 *gen)
+static int pcc_layout_rdonly_set(struct inode *inode, __u32 *gen, bool *cached)
{
struct ll_inode_info *lli = ll_i2info(inode);
RETURN(rc);
rc = ll_layout_refresh(inode, gen);
- if (rc)
- RETURN(rc);
} else { /* Readonly layout */
+ struct pcc_inode *pcci;
+
*gen = clt.cl_layout_gen;
+ /*
+ * The file is already in readonly state, give a chance to
+ * try auto attach.
+ */
+ pcc_inode_lock(inode);
+ pcci = ll_i2pcci(inode);
+ if (pcci && pcc_inode_has_layout(pcci))
+ *cached = true;
+ else
+ rc = pcc_try_datasets_attach(inode, PIT_OPEN, *gen,
+ LU_PCC_READONLY, cached);
+ pcc_inode_unlock(inode);
+ if (*cached)
+ ll_stats_ops_tally(ll_i2sbi(inode),
+ LPROC_LL_PCC_AUTOAT, 1);
}
RETURN(rc);
struct ll_inode_info *lli = ll_i2info(inode);
const struct cred *old_cred;
struct pcc_dataset *dataset;
- struct pcc_inode *pcci;
+ struct pcc_inode *pcci = NULL;
struct dentry *dentry;
bool attached = false;
bool unlinked = false;
+ bool cached = false;
__u32 gen;
int rc;
ENTRY;
- rc = pcc_layout_rdonly_set(inode, &gen);
+ rc = pcc_layout_rdonly_set(inode, &gen, &cached);
+ if (cached)
+ RETURN(0);
if (rc)
RETURN(rc);
pcc_inode_attach_set(super, dataset, lli, pcci,
dentry, LU_PCC_READONLY);
+ } else if (pcc_inode_has_layout(pcci)) {
+ /*
+ * There may be a gap between auto attach and auto open cache:
+ * ->pcc_file_open()
+ * ->pcc_try_auto_attach()
+ * The file is re-attach into PCC by other thread.
+ * ->pcc_try_readonly_open_attach()
+ */
+ GOTO(out_put_unlock, rc = -EEXIST);
} else {
atomic_inc(&pcci->pcci_refcount);
path_put(&pcci->pcci_path);
}
run_test 43 "Auto attach at open() should add capacity owner check"
+test_44() {
+ local loopfile="$TMP/$tfile"
+ local mntpt="/mnt/pcc.$tdir"
+ local hsm_root="$mntpt/$tdir"
+ local file=$DIR/$tfile
+ local count=50
+ local bs="1M"
+
+ setup_loopdev client $loopfile $mntpt 60
+ mkdir $hsm_root || error "mkdir $hsm_root failed"
+ setup_pcc_mapping client \
+ "projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1\ mmap_conv=0"
+ $LCTL pcc list $MOUNT
+ $LCTL set_param llite.*.pcc_async_threshold=1G
+
+ dd if=/dev/zero of=$file bs=$bs count=$count ||
+ error "Write $file failed"
+
+ local n=16
+ local lpid
+ local -a rpids
+
+ $LFS getstripe -v $file
+ clear_stats llite.*.stats
+
+ for ((i = 0; i < $n; i++)); do
+ (
+ while [ ! -e $DIR/$tfile.lck ]; do
+ dd if=$file of=/dev/null bs=$bs count=$count ||
+ error "Read $file failed"
+ sleep 0.$((RANDON % 4 + 1))
+ done
+ )&
+ rpids[$i]=$!
+ done
+
+ (
+ while [ ! -e $DIR/$tfile.lck ]; do
+ $LCTL set_param -n ldlm.namespaces.*mdc*.lru_size=clear ||
+ error "cancel_lru_locks mdc failed"
+ sleep 0.2
+ done
+ )&
+ lpid=$!
+
+ sleep 60
+ touch $DIR/$tfile.lck
+
+ for ((i = 0; i < $n; i++)); do
+ wait ${rpids[$i]} || error "$?: read failed"
+ done
+ wait $lpid || error "$?: lock cancel failed"
+
+ echo "Finish ========"
+ $LFS getstripe -v $file
+ $LCTL get_param llite.*.stats
+
+ local attach_num=$(calc_stats llite.*.stats pcc_attach)
+ local detach_num=$(calc_stats llite.*.stats pcc_detach)
+ local autoat_num=$(calc_stats llite.*.stats pcc_auto_attach)
+
+ echo "attach $attach_num detach $detach_num auto_attach $autoat_num"
+ [ $attach_num -eq 1 ] || error "attach more than 1 time: $attach_num"
+ rm -f $DIR/$tfile.lck
+}
+run_test 44 "Verify valid auto attach without re-fetching the whole files"
+
test_96() {
local loopfile="$TMP/$tfile"
local mntpt="/mnt/pcc.$tdir"
setup_pcc_mapping $SINGLEAGT \
"projid={0}\ roid=$HSM_ARCHIVE_NUMBER\ ropcc=1\ mmap_conv=0"
do_facet $SINGLEAGT $LCTL pcc list $MOUNT
- do_facet $SINGLEAGT $LCTL set_param llite.*.pcc_async_threshold=1G
+ do_facet $SINGLEAGT $LCTL set_param llite.*.pcc_async_threshold=0
local rpid1
local rpid2