]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd_types: add manifest type (chunked)
authormyoungwon oh <omwmw@sk.com>
Fri, 2 Jun 2017 04:14:20 +0000 (13:14 +0900)
committermyoungwon oh <omwmw@sk.com>
Thu, 2 Nov 2017 10:51:05 +0000 (19:51 +0900)
Signed-off-by: Myoungwon Oh <omwmw@sk.com>
src/osd/osd_types.cc
src/osd/osd_types.h

index ceced3cb40b7e1d65b05d378810bef197eb3dddc..d5d25eaa82bbfae910d5b1bbd88e8ff467e32808 100644 (file)
@@ -4834,6 +4834,44 @@ void watch_info_t::generate_test_instances(list<watch_info_t*>& o)
   o.back()->addr = ea;
 }
 
+// -- chunk_info_t --
+
+void chunk_info_t::encode(bufferlist& bl) const
+{
+  ENCODE_START(1, 1, bl);
+  ::encode(offset, bl);
+  ::encode(length, bl);
+  ::encode(oid, bl);
+  ::encode(flags, bl);
+  ENCODE_FINISH(bl);
+}
+
+void chunk_info_t::decode(bufferlist::iterator& bl)
+{
+  DECODE_START(1, bl);
+  ::decode(offset, bl);
+  ::decode(length, bl);
+  ::decode(oid, bl);
+  ::decode(flags, bl);
+  DECODE_FINISH(bl);
+}
+
+void chunk_info_t::dump(Formatter *f) const
+{
+  f->dump_unsigned("length", length);
+  f->open_object_section("oid");
+  oid.dump(f);
+  f->close_section();
+  f->dump_unsigned("flags", flags);
+}
+
+ostream& operator<<(ostream& out, const chunk_info_t& ci)
+{
+  return out << "(len: " << ci.length << " oid: " << ci.oid
+            << " offset: " << ci.offset
+            << " flags: " << ci.get_flag_string(ci.flags) << ")";
+}
+
 // -- object_manifest_t --
 
 void object_manifest_t::encode(bufferlist& bl) const
@@ -4845,6 +4883,9 @@ void object_manifest_t::encode(bufferlist& bl) const
     case TYPE_REDIRECT: 
       ::encode(redirect_target, bl);
       break;
+    case TYPE_CHUNKED:
+      ::encode(chunk_map, bl);      
+      break;
     default:
       ceph_abort();
   }
@@ -4860,6 +4901,9 @@ void object_manifest_t::decode(bufferlist::iterator& bl)
     case TYPE_REDIRECT: 
       ::decode(redirect_target, bl);
       break;
+    case TYPE_CHUNKED:
+      ::decode(chunk_map, bl);
+      break;
     default:
       ceph_abort();
   }
@@ -4869,9 +4913,20 @@ void object_manifest_t::decode(bufferlist::iterator& bl)
 void object_manifest_t::dump(Formatter *f) const
 {
   f->dump_unsigned("type", type);
-  f->open_object_section("redirect_target");
-  redirect_target.dump(f);
-  f->close_section();
+  if (type == TYPE_REDIRECT) {
+    f->open_object_section("redirect_target");
+    redirect_target.dump(f);
+    f->close_section();
+  } else if (type == TYPE_CHUNKED) {
+    f->open_array_section("chunk_map");
+    for (auto& p : chunk_map) {
+      f->open_object_section("chunk");
+      f->dump_unsigned("offset", p.first);
+      p.second.dump(f);
+      f->close_section();
+    }
+    f->close_section();
+  }
 }
 
 void object_manifest_t::generate_test_instances(list<object_manifest_t*>& o)
@@ -4882,7 +4937,14 @@ void object_manifest_t::generate_test_instances(list<object_manifest_t*>& o)
 
 ostream& operator<<(ostream& out, const object_manifest_t& om)
 {
-  return out << "type:" << om.type << " redirect_target:" << om.redirect_target;
+  out << "manifest(" << om.get_type_name();
+  if (om.is_redirect()) {
+    out << " " << om.redirect_target;
+  } else if (om.is_chunked()) {
+    out << " " << om.chunk_map;
+  }
+  out << ")";
+  return out;
 }
 
 // -- object_info_t --
index 33583e216393846c15dc5f46b6096a043c7d2646..f13e65bb6c622f1725fb4ca1399509d9c7c38b63 100644 (file)
@@ -4538,15 +4538,48 @@ static inline ostream& operator<<(ostream& out, const notify_info_t& n) {
             << " " << n.timeout << "s)";
 }
 
+struct chunk_info_t {
+  enum {
+    FLAG_DIRTY = 1, 
+    FLAG_MISSING = 2,
+  };
+  uint32_t offset;
+  uint32_t length;
+  hobject_t oid;
+  uint32_t flags;   // FLAG_*
+
+  chunk_info_t() : length(0), flags(0) { }
+
+  static string get_flag_string(uint64_t flags) {
+    string r;
+    if (flags & FLAG_DIRTY) {
+      r += "|dirty";
+    }
+    if (flags & FLAG_MISSING) {
+      r += "|missing";
+    }
+    if (r.length())
+      return r.substr(1);
+    return r;
+  }
+  void encode(bufferlist &bl) const;
+  void decode(bufferlist::iterator &bl);
+  void dump(Formatter *f) const;
+  friend ostream& operator<<(ostream& out, const chunk_info_t& ci);
+};
+WRITE_CLASS_ENCODER(chunk_info_t)
+ostream& operator<<(ostream& out, const chunk_info_t& ci);
+
 struct object_info_t;
 struct object_manifest_t {
   enum {
     TYPE_NONE = 0,
-    TYPE_REDIRECT = 1,  // start with this
-    TYPE_CHUNKED = 2,   // do this later
+    TYPE_REDIRECT = 1, 
+    TYPE_CHUNKED = 2, 
   };
   uint8_t type;  // redirect, chunked, ...
   hobject_t redirect_target;
+  map <uint64_t, chunk_info_t> chunk_map;
 
   object_manifest_t() : type(0) { }
   object_manifest_t(uint8_t type, const hobject_t& redirect_target) 
@@ -4572,6 +4605,11 @@ struct object_manifest_t {
   const char *get_type_name() const {
     return get_type_name(type);
   }
+  void clear() {
+    type = 0;
+    redirect_target = hobject_t();
+    chunk_map.clear();
+  }
   static void generate_test_instances(list<object_manifest_t*>& o);
   void encode(bufferlist &bl) const;
   void decode(bufferlist::iterator &bl);