]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: add flag interfaces in chunk_info_t
authormyoungwon oh <omwmw@sk.com>
Sat, 11 Aug 2018 16:10:18 +0000 (01:10 +0900)
committermyoungwon oh <omwmw@sk.com>
Fri, 7 Sep 2018 11:58:09 +0000 (20:58 +0900)
This commit change the inferface of set/get/clear flag
in order to handle bitwise operation

Signed-off-by: Myoungwon Oh <omwmw@sk.com>
src/osd/PrimaryLogPG.cc
src/osd/osd_types.cc
src/osd/osd_types.h

index f5eb85cec342e18372c910d1eba46b81c72b1889..94f51a258166074f39b233e0858ecbde6df0cc0c 100644 (file)
@@ -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<const MOSDOp*>(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<uint64_t, chunk_info_t>::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<OSDOp>& 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<OSDOp>& 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<OSDOp>& 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
        }
       }
     }
index 26e3a244250807bbf05f101746ee856cca685f7d..407d259dc21bef3046338bec8ca2e5316e45dae9 100644 (file)
@@ -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);
 }
 
index 173a21387058444e6569c3dce961381472d96096..4cbb4084f046771592ed8aa56f491ea76a80dd7d 100644 (file)
@@ -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;