From: myoungwon oh Date: Sat, 11 Aug 2018 16:10:18 +0000 (+0900) Subject: osd: add flag interfaces in chunk_info_t X-Git-Tag: v14.0.1~340^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4efb0b60070c07b1c5e482a217d17aa138e7b3d7;p=ceph.git osd: add flag interfaces in chunk_info_t This commit change the inferface of set/get/clear flag in order to handle bitwise operation Signed-off-by: Myoungwon Oh --- diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index f5eb85cec342..94f51a258166 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -2473,7 +2473,7 @@ PrimaryLogPG::cache_result_t PrimaryLogPG::maybe_handle_manifest_detail( } for (auto& p : obc->obs.oi.manifest.chunk_map) { - if (p.second.flags == chunk_info_t::FLAG_MISSING) { + if (p.second.is_missing()) { const MOSDOp *m = static_cast(op->get_req()); const object_locator_t oloc = m->get_object_locator(); promote_object(obc, obc->obs.oi.soid, oloc, op, NULL); @@ -2483,7 +2483,7 @@ PrimaryLogPG::cache_result_t PrimaryLogPG::maybe_handle_manifest_detail( bool all_dirty = true; for (auto& p : obc->obs.oi.manifest.chunk_map) { - if (p.second.flags != chunk_info_t::FLAG_DIRTY) { + if (!p.second.is_dirty()) { all_dirty = false; } } @@ -2579,7 +2579,7 @@ int PrimaryLogPG::do_manifest_flush(OpRequestRef op, ObjectContextRef obc, Flush map::iterator iter = manifest.chunk_map.find(start_offset); ceph_assert(iter != manifest.chunk_map.end()); for (;iter != manifest.chunk_map.end(); ++iter) { - if (iter->second.flags == chunk_info_t::FLAG_DIRTY) { + if (iter->second.is_dirty()) { last_offset = iter->first; max_copy_size += iter->second.length; } @@ -2590,7 +2590,7 @@ int PrimaryLogPG::do_manifest_flush(OpRequestRef op, ObjectContextRef obc, Flush iter = manifest.chunk_map.find(start_offset); for (;iter != manifest.chunk_map.end(); ++iter) { - if (iter->second.flags != chunk_info_t::FLAG_DIRTY) { + if (!iter->second.is_dirty()) { continue; } uint64_t tgt_length = iter->second.length; @@ -2652,7 +2652,7 @@ void PrimaryLogPG::finish_manifest_flush(hobject_t oid, ceph_tid_t tid, int r, obc->obs.oi.manifest.chunk_map.find(last_offset); ceph_assert(iter != obc->obs.oi.manifest.chunk_map.end()); for (;iter != obc->obs.oi.manifest.chunk_map.end(); ++iter) { - if (iter->second.flags == chunk_info_t::FLAG_DIRTY && last_offset < iter->first) { + if (iter->second.is_dirty() && last_offset < iter->first) { do_manifest_flush(p->second->op, obc, p->second, iter->first, p->second->blocking); return; } @@ -3558,7 +3558,7 @@ bool PrimaryLogPG::can_proxy_chunked_read(OpRequestRef op, ObjectContextRef obc) /* requested chunks exist in chunk_map ? */ for (auto &p : obc->obs.oi.manifest.chunk_map) { if (p.first <= cursor && p.first + p.second.length > cursor) { - if (p.second.flags != chunk_info_t::FLAG_MISSING) { + if (!p.second.is_missing()) { return false; } if (p.second.length >= remain) { @@ -6590,7 +6590,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector& ops) ctx->register_on_commit( [oi, ctx, this](){ for (auto p : oi.manifest.chunk_map) { - if (p.second.flags & chunk_info_t::FLAG_HAS_REFERENCE) { + if (p.second.has_reference()) { object_locator_t target_oloc(p.second.oid); refcount_manifest(ctx->obc, target_oloc, p.second.oid, SnapContext(), false, NULL, p.first); @@ -6916,7 +6916,7 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector& ops) } chunk_info_t chunk_info; - chunk_info.flags = chunk_info_t::FLAG_MISSING; + chunk_info.set_flag(chunk_info_t::FLAG_MISSING); chunk_info.oid = target; chunk_info.offset = tgt_offset; chunk_info.length= src_length; @@ -6926,11 +6926,10 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector& ops) oi.set_flag(object_info_t::FLAG_MANIFEST); oi.manifest.type = object_manifest_t::TYPE_CHUNKED; if (!has_reference && need_reference) { - oi.manifest.chunk_map[src_offset].flags |= - chunk_info_t::FLAG_HAS_REFERENCE; + oi.manifest.chunk_map[src_offset].set_flag(chunk_info_t::FLAG_HAS_REFERENCE); } if (need_reference && pool.info.get_fingerprint_type() != pg_pool_t::TYPE_FINGERPRINT_NONE) { - oi.manifest.chunk_map[src_offset].flags |= chunk_info_t::FLAG_HAS_FINGERPRINT; + oi.manifest.chunk_map[src_offset].set_flag(chunk_info_t::FLAG_HAS_FINGERPRINT); } ctx->modify = true; @@ -8134,7 +8133,8 @@ void PrimaryLogPG::write_update_size_and_usage(object_stat_sum_t& delta_stats, o for (auto &p : oi.manifest.chunk_map) { if ((p.first <= offset && p.first + p.second.length > offset) || (p.first > offset && p.first <= offset + length)) { - p.second.flags = chunk_info_t::FLAG_DIRTY; + p.second.clear_flag(chunk_info_t::FLAG_MISSING); + p.second.set_flag(chunk_info_t::FLAG_DIRTY); } } } @@ -9244,7 +9244,8 @@ void PrimaryLogPG::process_copy_chunk_manifest(hobject_t oid, ceph_tid_t tid, in << " length: " << sub_chunk.outdata.length() << dendl; write_update_size_and_usage(ctx->delta_stats, obs.oi, ctx->modified_ranges, p.second->cursor.data_offset, sub_chunk.outdata.length()); - obs.oi.manifest.chunk_map[p.second->cursor.data_offset].flags = 0; // clean + obs.oi.manifest.chunk_map[p.second->cursor.data_offset].clear_flag(chunk_info_t::FLAG_DIRTY); + obs.oi.manifest.chunk_map[p.second->cursor.data_offset].clear_flag(chunk_info_t::FLAG_MISSING); sub_chunk.outdata.clear(); } obs.oi.clear_data_digest(); @@ -10147,14 +10148,16 @@ int PrimaryLogPG::try_flush_mark_clean(FlushOpRef fop) 0); ctx->new_obs.oi.new_object(); for (auto &p : ctx->new_obs.oi.manifest.chunk_map) { - p.second.flags = chunk_info_t::FLAG_MISSING; + p.second.clear_flag(chunk_info_t::FLAG_DIRTY); + p.second.set_flag(chunk_info_t::FLAG_MISSING); } } else { for (auto &p : ctx->new_obs.oi.manifest.chunk_map) { - if (p.second.flags == chunk_info_t::FLAG_DIRTY) { + if (p.second.is_dirty()) { dout(20) << __func__ << " offset: " << p.second.offset << " length: " << p.second.length << dendl; - p.second.flags = 0; // CLEAN + p.second.clear_flag(chunk_info_t::FLAG_DIRTY); + p.second.clear_flag(chunk_info_t::FLAG_MISSING); // CLEAN } } } diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 26e3a2442508..407d259dc21b 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -4972,7 +4972,8 @@ void chunk_info_t::encode(bufferlist& bl) const encode(offset, bl); encode(length, bl); encode(oid, bl); - encode(flags, bl); + __u32 _flags = flags; + encode(_flags, bl); ENCODE_FINISH(bl); } @@ -4982,7 +4983,9 @@ void chunk_info_t::decode(bufferlist::const_iterator& bl) decode(offset, bl); decode(length, bl); decode(oid, bl); - decode(flags, bl); + __u32 _flags; + decode(_flags, bl); + flags = (cflag_t)_flags; DECODE_FINISH(bl); } diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 173a21387058..4cbb4084f046 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -4605,18 +4605,18 @@ static inline ostream& operator<<(ostream& out, const notify_info_t& n) { } struct chunk_info_t { - enum { + typedef enum { FLAG_DIRTY = 1, FLAG_MISSING = 2, FLAG_HAS_REFERENCE = 4, FLAG_HAS_FINGERPRINT = 8, - }; + } cflag_t; uint32_t offset; uint32_t length; hobject_t oid; - uint32_t flags; // FLAG_* + cflag_t flags; // FLAG_* - chunk_info_t() : offset(0), length(0), flags(0) { } + chunk_info_t() : offset(0), length(0), flags((cflag_t)0) { } static string get_flag_string(uint64_t flags) { string r; @@ -4636,6 +4636,33 @@ struct chunk_info_t { return r.substr(1); return r; } + bool test_flag(cflag_t f) const { + return (flags & f) == f; + } + void set_flag(cflag_t f) { + flags = (cflag_t)(flags | f); + } + void set_flags(cflag_t f) { + flags = f; + } + void clear_flag(cflag_t f) { + flags = (cflag_t)(flags & ~f); + } + void clear_flags() { + flags = (cflag_t)0; + } + bool is_dirty() const { + return test_flag(FLAG_DIRTY); + } + bool is_missing() const { + return test_flag(FLAG_MISSING); + } + bool has_reference() const { + return test_flag(FLAG_HAS_REFERENCE); + } + bool has_fingerprint() const { + return test_flag(FLAG_HAS_FINGERPRINT); + } void encode(bufferlist &bl) const; void decode(bufferlist::const_iterator &bl); void dump(Formatter *f) const;