}
CLS_LOG(10, "fp_oid: %s \n", fp_oid.c_str());
- bool ret = cls_has_chunk(hctx, fp_oid);
+ int ret = cls_get_manifest_ref_count(hctx, fp_oid);
if (ret) {
- return 0;
+ return ret;
}
return -ENOLINK;
}
return 0;
}
-bool cls_has_chunk(cls_method_context_t hctx, string fp_oid)
+int cls_get_manifest_ref_count(cls_method_context_t hctx, string fp_oid)
{
return 0;
}
int cls_cxx_chunk_write_and_set(cls_method_context_t hctx, int ofs, int len,
ceph::buffer::list *write_inbl, uint32_t op_flags, ceph::buffer::list *set_inbl,
int set_len);
-bool cls_has_chunk(cls_method_context_t hctx, std::string fp_oid);
+int cls_get_manifest_ref_count(cls_method_context_t hctx, std::string fp_oid);
extern uint64_t cls_get_osd_min_alloc_size(cls_method_context_t hctx);
extern uint64_t cls_get_pool_stripe_width(cls_method_context_t hctx);
}
}
-bool PrimaryLogPG::has_manifest_chunk(ObjectContextRef obc, std::string& fp_oid)
+int PrimaryLogPG::get_manifest_ref_count(ObjectContextRef obc, std::string& fp_oid)
{
+ int cnt = 0;
// head
for (auto &p : obc->obs.oi.manifest.chunk_map) {
if (p.second.oid.oid.name == fp_oid) {
- return true;
+ cnt++;
}
}
// snap
SnapSet& ss = obc->ssc->snapset;
- for (vector<snapid_t>::const_iterator p = ss.clones.begin();
- p != ss.clones.end();
+ for (vector<snapid_t>::const_reverse_iterator p = ss.clones.rbegin();
+ p != ss.clones.rend();
++p) {
+ object_ref_delta_t refs;
+ ObjectContextRef obc_l = nullptr;
+ ObjectContextRef obc_g = nullptr;
hobject_t clone_oid = obc->obs.oi.soid;
clone_oid.snap = *p;
ObjectContextRef clone_obc = get_object_context(clone_oid, false);
- if (clone_obc && clone_obc->obs.oi.has_manifest()) {
- for (auto &p : clone_obc->obs.oi.manifest.chunk_map) {
- if (p.second.oid.oid.name == fp_oid) {
- return true;
+ if (!clone_obc) {
+ break;
+ }
+ get_adjacent_clones(clone_obc, obc_l, obc_g);
+ clone_obc->obs.oi.manifest.calc_refs_to_inc_on_set(
+ obc_g ? &(obc_g->obs.oi.manifest) : nullptr ,
+ nullptr,
+ refs);
+ if (!refs.is_empty()) {
+ for (auto p = refs.begin(); p != refs.end(); ++p) {
+ if (p->first.oid.name == fp_oid && p->second > 0) {
+ cnt += p->second;
}
}
}
}
- return false;
+ return cnt;
}
ObjectContextRef PrimaryLogPG::get_prev_clone_obc(ObjectContextRef obc)
void maybe_kick_recovery(const hobject_t &soid);
void wait_for_unreadable_object(const hobject_t& oid, OpRequestRef op);
- bool has_manifest_chunk(ObjectContextRef obc, std::string& fp_oid);
+ int get_manifest_ref_count(ObjectContextRef obc, std::string& fp_oid);
bool check_laggy(OpRequestRef& op);
bool check_laggy_requeue(OpRequestRef& op);
return (*pctx)->pg->do_osd_ops(*pctx, ops);
}
-bool cls_has_chunk(cls_method_context_t hctx, string fp_oid)
+int cls_get_manifest_ref_count(cls_method_context_t hctx, string fp_oid)
{
PrimaryLogPG::OpContext *ctx = *(PrimaryLogPG::OpContext **)hctx;
- return ctx->pg->has_manifest_chunk(ctx->obc, fp_oid);
+ return ctx->pg->get_manifest_ref_count(ctx->obc, fp_oid);
}
uint64_t cls_get_osd_min_alloc_size(cls_method_context_t hctx) {
// create object
{
bufferlist bl;
- bl.append("there hiHI");
+ bl.append("there HIHI");
ObjectWriteOperation op;
op.write_full(bl);
ASSERT_EQ(0, ioctx.operate("foo", &op));
}
// set-chunk (dedup)
- manifest_set_chunk(cluster, cache_ioctx, ioctx, 6, 2, hi_fp_oid, "foo");
+ manifest_set_chunk(cluster, cache_ioctx, ioctx, 6, 2, HI_fp_oid, "foo");
// set-chunk (dedup)
manifest_set_chunk(cluster, cache_ioctx, ioctx, 8, 2, HI_fp_oid, "foo");
ASSERT_EQ(0, ioctx.write("foo", bl, 1, 6));
}
- // foo snap[1]: [hi] [HI]
+ // foo snap[1]: [HI] [HI]
// foo snap[0]: [er] [ai] [SI]
// foo head : [er] [bi] [SI]
// set-chunk (dedup)
manifest_set_chunk(cluster, cache_ioctx, ioctx, 6, 2, bi_fp_oid, "foo");
-
{
- ASSERT_EQ(0, cls_cas_references_chunk(ioctx, "foo", SI_fp_oid));
- ASSERT_EQ(0, cls_cas_references_chunk(ioctx, "foo", er_fp_oid));
- ASSERT_EQ(0, cls_cas_references_chunk(ioctx, "foo", ai_fp_oid));
- ASSERT_EQ(0, cls_cas_references_chunk(ioctx, "foo", HI_fp_oid));
+ ASSERT_EQ(1, cls_cas_references_chunk(ioctx, "foo", SI_fp_oid));
+ ASSERT_EQ(1, cls_cas_references_chunk(ioctx, "foo", er_fp_oid));
+ ASSERT_EQ(1, cls_cas_references_chunk(ioctx, "foo", ai_fp_oid));
+ ASSERT_EQ(2, cls_cas_references_chunk(ioctx, "foo", HI_fp_oid));
ASSERT_EQ(-ENOLINK, cls_cas_references_chunk(ioctx, "foo", Hi_fp_oid));
}
}