]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-dencoder: add hobject_t
authorSage Weil <sage.weil@dreamhost.com>
Fri, 10 Feb 2012 05:30:16 +0000 (21:30 -0800)
committerSage Weil <sage.weil@dreamhost.com>
Fri, 10 Feb 2012 05:30:16 +0000 (21:30 -0800)
Move to a separate file in os/, since this is an ObjectStore related
object.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/Makefile.am
src/include/object.h
src/include/types.h
src/os/hobject.cc [new file with mode: 0644]
src/os/hobject.h [new file with mode: 0644]
src/osd/osd_types.h
src/test/encoding/types.h

index 45660b0a26b68e3d63dd4c55ee9475a0cf01b722..96c994f148f8981fb2e566b005c0ddd0316dd02c 100644 (file)
@@ -903,6 +903,7 @@ libcommon_files = \
        mon/MonCaps.cc \
        mon/MonClient.cc \
        mon/MonMap.cc \
+       os/hobject.cc \
        osd/OSDMap.cc \
        osd/osd_types.cc \
        mds/MDSMap.cc \
@@ -1389,6 +1390,7 @@ noinst_HEADERS = \
        obsync/obsync\
        obsync/boto_tool\
        os/btrfs_ioctl.h\
+       os/hobject.h \
        os/CollectionIndex.h\
         os/Fake.h\
         os/FileJournal.h\
index b5654f501e0b51f94eee4b43ddb55f94d6b89e4d..4f9bd5fe9040fed48993446550301fbf68609eae 100644 (file)
@@ -264,147 +264,4 @@ namespace __gnu_cxx {
   };
 }
 
-typedef uint64_t filestore_hobject_key_t;
-struct hobject_t {
-  object_t oid;
-  snapid_t snap;
-  uint32_t hash;
-  bool max;
-
-private:
-  string key;
-
-public:
-  const string &get_key() const {
-    return key;
-  }
-  
-  hobject_t() : snap(0), hash(0), max(false) {}
-
-  hobject_t(object_t oid, const string& key, snapid_t snap, uint64_t hash) : 
-    oid(oid), snap(snap), hash(hash), max(false),
-    key(oid.name == key ? string() : key) {}
-
-  hobject_t(const sobject_t &soid, const string &key, uint32_t hash) : 
-    oid(soid.oid), snap(soid.snap), hash(hash), max(false),
-    key(soid.oid.name == key ? string() : key) {}
-
-  /* Do not use when a particular hash function is needed */
-  explicit hobject_t(const sobject_t &o) :
-    oid(o.oid), snap(o.snap), max(false) {
-    hash = __gnu_cxx::hash<sobject_t>()(o);
-  }
-
-  // maximum sorted value.
-  static hobject_t get_max() {
-    hobject_t h;
-    h.max = true;
-    return h;
-  }
-  bool is_max() const {
-    return max;
-  }
-
-  static uint32_t _reverse_nibbles(uint32_t retval) {
-    // reverse nibbles
-    retval = ((retval & 0x0f0f0f0f) << 4) | ((retval & 0xf0f0f0f0) >> 4);
-    retval = ((retval & 0x00ff00ff) << 8) | ((retval & 0xff00ff00) >> 8);
-    retval = ((retval & 0x0000ffff) << 16) | ((retval & 0xffff0000) >> 16);
-    return retval;
-  }
-
-  filestore_hobject_key_t get_filestore_key() const {
-    if (max)
-      return 0x100000000ull;
-    else
-      return _reverse_nibbles(hash);
-  }
-  void set_filestore_key(uint32_t v) {
-    hash = _reverse_nibbles(v);
-  }
-
-  const string& get_effective_key() const {
-    if (key.length())
-      return key;
-    return oid.name;
-  }
-
-  /**
-   * back up hobject_t to beginning of hash bucket, if i am partway through one.
-   */
-  void back_up_to_bounding_key() {
-    if (key.length()) {
-      oid.clear();
-    } else {
-      key = oid.name;
-      oid.clear();
-    }
-    snap = 0;
-  }
-
-  void swap(hobject_t &o) {
-    hobject_t temp(o);
-    o.oid = oid;
-    o.key = key;
-    o.snap = snap;
-    o.hash = hash;
-    oid = temp.oid;
-    key = temp.key;
-    snap = temp.snap;
-    hash = temp.hash;
-  }
-
-  void encode(bufferlist& bl) const {
-    __u8 version = 2;
-    ::encode(version, bl);
-    ::encode(key, bl);
-    ::encode(oid, bl);
-    ::encode(snap, bl);
-    ::encode(hash, bl);
-    ::encode(max, bl);
-  }
-  void decode(bufferlist::iterator& bl) {
-    __u8 version;
-    ::decode(version, bl);
-    if (version >= 1)
-      ::decode(key, bl);
-    ::decode(oid, bl);
-    ::decode(snap, bl);
-    ::decode(hash, bl);
-    if (version >= 2)
-      ::decode(max, bl);
-    else
-      max = false;
-  }
-};
-WRITE_CLASS_ENCODER(hobject_t)
-
-namespace __gnu_cxx {
-  template<> struct hash<hobject_t> {
-    size_t operator()(const hobject_t &r) const {
-      static hash<object_t> H;
-      static rjhash<uint64_t> I;
-      return H(r.oid) ^ I(r.snap);
-    }
-  };
-}
-
-inline ostream& operator<<(ostream& out, const hobject_t& o)
-{
-  if (o.is_max())
-    return out << "MAX";
-  out << std::hex << o.hash << std::dec;
-  if (o.get_key().length())
-    out << "." << o.get_key();
-  out << "/" << o.oid << "/" << o.snap;
-  return out;
-}
-
-WRITE_EQ_OPERATORS_5(hobject_t, oid, get_key(), snap, hash, max)
-// sort hobject_t's by <max, get_filestore_key(hash), key, oid, snapid>
-WRITE_CMP_OPERATORS_5(hobject_t, max, get_filestore_key(), get_effective_key(), oid, snap)
-
-
-// ---------------------------
-
 #endif
index bb753163ddf95606b242894db2f374a8f883f1fa..f99c5f7268e19e9d9b4d6204cfb52f7d953c106d 100644 (file)
@@ -348,8 +348,6 @@ static inline bool file_mode_is_readonly(int mode) {
 }
 
 
-typedef hobject_t collection_list_handle_t;
-
 // dentries
 #define MAX_DENTRY_LEN 255
 
diff --git a/src/os/hobject.cc b/src/os/hobject.cc
new file mode 100644 (file)
index 0000000..113cf76
--- /dev/null
@@ -0,0 +1,60 @@
+
+#include "include/types.h"
+#include "hobject.h"
+#include "common/Formatter.h"
+
+void hobject_t::encode(bufferlist& bl) const
+{
+  __u8 version = 2;
+  ::encode(version, bl);
+  ::encode(key, bl);
+  ::encode(oid, bl);
+  ::encode(snap, bl);
+  ::encode(hash, bl);
+  ::encode(max, bl);
+}
+
+void hobject_t::decode(bufferlist::iterator& bl)
+{
+  __u8 version;
+  ::decode(version, bl);
+  if (version >= 1)
+    ::decode(key, bl);
+  ::decode(oid, bl);
+  ::decode(snap, bl);
+  ::decode(hash, bl);
+  if (version >= 2)
+    ::decode(max, bl);
+  else
+    max = false;
+}
+
+void hobject_t::dump(Formatter *f) const
+{
+  f->dump_string("oid", oid.name);
+  f->dump_string("key", key);
+  f->dump_int("snapid", snap);
+  f->dump_int("hash", hash);
+  f->dump_int("max", (int)max);
+}
+
+void hobject_t::generate_test_instances(list<hobject_t*>& o)
+{
+  o.push_back(new hobject_t);
+  o.push_back(new hobject_t);
+  o.back()->max = true;
+  o.push_back(new hobject_t(object_t("oname"), string(), 1, 234));
+  o.push_back(new hobject_t(object_t("oname2"), string("okey"), CEPH_NOSNAP, 67));
+  o.push_back(new hobject_t(object_t("oname3"), string("oname3"), CEPH_SNAPDIR, 910));
+}
+
+ostream& operator<<(ostream& out, const hobject_t& o)
+{
+  if (o.is_max())
+    return out << "MAX";
+  out << std::hex << o.hash << std::dec;
+  if (o.get_key().length())
+    out << "." << o.get_key();
+  out << "/" << o.oid << "/" << o.snap;
+  return out;
+}
diff --git a/src/os/hobject.h b/src/os/hobject.h
new file mode 100644 (file)
index 0000000..87cd470
--- /dev/null
@@ -0,0 +1,140 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software 
+ * Foundation.  See file COPYING.
+ * 
+ */
+
+#ifndef __CEPH_OS_HOBJECT_H
+#define __CEPH_OS_HOBJECT_H
+
+#include "include/object.h"
+#include "include/cmp.h"
+
+typedef uint64_t filestore_hobject_key_t;
+
+namespace ceph {
+  class Formatter;
+}
+
+struct hobject_t {
+  object_t oid;
+  snapid_t snap;
+  uint32_t hash;
+  bool max;
+
+private:
+  string key;
+
+public:
+  const string &get_key() const {
+    return key;
+  }
+  
+  hobject_t() : snap(0), hash(0), max(false) {}
+
+  hobject_t(object_t oid, const string& key, snapid_t snap, uint64_t hash) : 
+    oid(oid), snap(snap), hash(hash), max(false),
+    key(oid.name == key ? string() : key) {}
+
+  hobject_t(const sobject_t &soid, const string &key, uint32_t hash) : 
+    oid(soid.oid), snap(soid.snap), hash(hash), max(false),
+    key(soid.oid.name == key ? string() : key) {}
+
+  /* Do not use when a particular hash function is needed */
+  explicit hobject_t(const sobject_t &o) :
+    oid(o.oid), snap(o.snap), max(false) {
+    hash = __gnu_cxx::hash<sobject_t>()(o);
+  }
+
+  // maximum sorted value.
+  static hobject_t get_max() {
+    hobject_t h;
+    h.max = true;
+    return h;
+  }
+  bool is_max() const {
+    return max;
+  }
+
+  static uint32_t _reverse_nibbles(uint32_t retval) {
+    // reverse nibbles
+    retval = ((retval & 0x0f0f0f0f) << 4) | ((retval & 0xf0f0f0f0) >> 4);
+    retval = ((retval & 0x00ff00ff) << 8) | ((retval & 0xff00ff00) >> 8);
+    retval = ((retval & 0x0000ffff) << 16) | ((retval & 0xffff0000) >> 16);
+    return retval;
+  }
+
+  filestore_hobject_key_t get_filestore_key() const {
+    if (max)
+      return 0x100000000ull;
+    else
+      return _reverse_nibbles(hash);
+  }
+  void set_filestore_key(uint32_t v) {
+    hash = _reverse_nibbles(v);
+  }
+
+  const string& get_effective_key() const {
+    if (key.length())
+      return key;
+    return oid.name;
+  }
+
+  /**
+   * back up hobject_t to beginning of hash bucket, if i am partway through one.
+   */
+  void back_up_to_bounding_key() {
+    if (key.length()) {
+      oid.clear();
+    } else {
+      key = oid.name;
+      oid.clear();
+    }
+    snap = 0;
+  }
+
+  void swap(hobject_t &o) {
+    hobject_t temp(o);
+    o.oid = oid;
+    o.key = key;
+    o.snap = snap;
+    o.hash = hash;
+    oid = temp.oid;
+    key = temp.key;
+    snap = temp.snap;
+    hash = temp.hash;
+  }
+
+  void encode(bufferlist& bl) const;
+  void decode(bufferlist::iterator& bl);
+  void dump(Formatter *f) const;
+  static void generate_test_instances(list<hobject_t*>& o);
+};
+WRITE_CLASS_ENCODER(hobject_t)
+
+namespace __gnu_cxx {
+  template<> struct hash<hobject_t> {
+    size_t operator()(const hobject_t &r) const {
+      static hash<object_t> H;
+      static rjhash<uint64_t> I;
+      return H(r.oid) ^ I(r.snap);
+    }
+  };
+}
+
+ostream& operator<<(ostream& out, const hobject_t& o);
+
+WRITE_EQ_OPERATORS_5(hobject_t, oid, get_key(), snap, hash, max)
+// sort hobject_t's by <max, get_filestore_key(hash), key, oid, snapid>
+WRITE_CMP_OPERATORS_5(hobject_t, max, get_filestore_key(), get_effective_key(), oid, snap)
+
+
+#endif
index 262a10bca8b636664b79def6fe3188c8f16f4a39..23dde8eff25d3c08e9027a84a6e03b257c4bda3a 100644 (file)
@@ -26,7 +26,7 @@
 #include "include/interval_set.h"
 #include "common/snap_types.h"
 #include "common/Formatter.h"
-
+#include "os/hobject.h"
 
 
 #define CEPH_OSD_ONDISK_MAGIC "ceph osd volume v026"
 #define CEPH_OSD_FEATURE_INCOMPAT_CATEGORIES  CompatSet::Feature(5, "categories")
 
 
-/* osdreqid_t - caller name + incarnation# + tid to unique identify this request
- * use for metadata and osd ops.
+typedef hobject_t collection_list_handle_t;
+
+
+/**
+ * osd request identifier
+ *
+ * caller name + incarnation# + tid to unique identify this request.
  */
 struct osd_reqid_t {
   entity_name_t name; // who
index f02afdd61cb7dc3c9741b00f9d4e9cea8a3e9e77..131b3a24e60d1511e25ab6fc4c8e19782cac2443 100644 (file)
@@ -54,6 +54,9 @@ TYPE(ScrubMap)
 #include "os/ObjectStore.h"
 TYPE(ObjectStore::Transaction)
 
+#include "os/hobject.h"
+TYPE(hobject_t)
+
 #include "mon/PGMap.h"
 TYPE(PGMap::Incremental)
 TYPE(PGMap)