From: Roald J. van Loon Date: Sat, 7 Sep 2013 13:16:27 +0000 (+0200) Subject: automake cleanup: moving hobject from os to common X-Git-Tag: v0.71~163^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bb312b689a6e8824cac0c6dd64cccb0152d788d1;p=ceph.git automake cleanup: moving hobject from os to common This file is used by libcommon, so lets put it in src/common instead of src/os. Signed-off-by: Roald J. van Loon --- diff --git a/src/Makefile.am b/src/Makefile.am index cf08504a76d1..9380a8ed8cf8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1594,7 +1594,7 @@ libcommon_files = \ msg/Pipe.cc \ msg/SimpleMessenger.cc \ msg/msg_types.cc \ - os/hobject.cc \ + common/hobject.cc \ osd/OSDMap.cc \ osd/osd_types.cc \ mds/MDSMap.cc \ @@ -2240,7 +2240,7 @@ noinst_HEADERS = \ os/btrfs_ioctl.h\ os/ZFS.h\ os/chain_xattr.h\ - os/hobject.h \ + common/hobject.h \ os/CollectionIndex.h\ os/FileJournal.h\ os/FileStore.h\ diff --git a/src/common/hobject.cc b/src/common/hobject.cc new file mode 100644 index 000000000000..d6273693c623 --- /dev/null +++ b/src/common/hobject.cc @@ -0,0 +1,193 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "include/types.h" +#include "hobject.h" +#include "common/Formatter.h" + +static void append_escaped(const string &in, string *out) +{ + for (string::const_iterator i = in.begin(); i != in.end(); ++i) { + if (*i == '%') { + out->push_back('%'); + out->push_back('p'); + } else if (*i == '.') { + out->push_back('%'); + out->push_back('e'); + } else if (*i == '_') { + out->push_back('%'); + out->push_back('u'); + } else { + out->push_back(*i); + } + } +} + +set hobject_t::get_prefixes( + uint32_t bits, + uint32_t mask, + int64_t pool) +{ + uint32_t len = bits; + while (len % 4 /* nibbles */) len++; + + set from; + if (bits < 32) + from.insert(mask & ~((uint32_t)(~0) << bits)); + else if (bits == 32) + from.insert(mask); + else + assert(0); + + + set to; + for (uint32_t i = bits; i < len; ++i) { + for (set::iterator j = from.begin(); + j != from.end(); + ++j) { + to.insert(*j | (1 << i)); + to.insert(*j); + } + to.swap(from); + to.clear(); + } + + char buf[20]; + char *t = buf; + uint64_t poolid(pool); + t += snprintf(t, sizeof(buf), "%.*llX", 16, (long long unsigned)poolid); + *(t++) = '.'; + string poolstr(buf, t - buf); + set ret; + for (set::iterator i = from.begin(); + i != from.end(); + ++i) { + uint32_t revhash(hobject_t::_reverse_nibbles(*i)); + snprintf(buf, sizeof(buf), "%.*X", (int)(sizeof(revhash))*2, revhash); + ret.insert(poolstr + string(buf, len/4)); + } + return ret; +} + +string hobject_t::to_str() const +{ + string out; + + char snap_with_hash[1000]; + char *t = snap_with_hash; + char *end = t + sizeof(snap_with_hash); + + uint64_t poolid(pool); + t += snprintf(t, end - t, "%.*llX", 16, (long long unsigned)poolid); + + uint32_t revhash(get_filestore_key_u32()); + t += snprintf(t, end - t, ".%.*X", 8, revhash); + + if (snap == CEPH_NOSNAP) + t += snprintf(t, end - t, ".head"); + else if (snap == CEPH_SNAPDIR) + t += snprintf(t, end - t, ".snapdir"); + else + t += snprintf(t, end - t, ".%llx", (long long unsigned)snap); + + out += string(snap_with_hash); + + out.push_back('.'); + append_escaped(oid.name, &out); + out.push_back('.'); + append_escaped(get_key(), &out); + out.push_back('.'); + append_escaped(nspace, &out); + + return out; +} + +void hobject_t::encode(bufferlist& bl) const +{ + ENCODE_START(4, 3, bl); + ::encode(key, bl); + ::encode(oid, bl); + ::encode(snap, bl); + ::encode(hash, bl); + ::encode(max, bl); + ::encode(nspace, bl); + ::encode(pool, bl); + ENCODE_FINISH(bl); +} + +void hobject_t::decode(bufferlist::iterator& bl) +{ + DECODE_START_LEGACY_COMPAT_LEN(4, 3, 3, bl); + if (struct_v >= 1) + ::decode(key, bl); + ::decode(oid, bl); + ::decode(snap, bl); + ::decode(hash, bl); + if (struct_v >= 2) + ::decode(max, bl); + else + max = false; + if (struct_v >= 4) { + ::decode(nspace, bl); + ::decode(pool, bl); + } + DECODE_FINISH(bl); +} + +void hobject_t::decode(json_spirit::Value& v) +{ + using namespace json_spirit; + Object& o = v.get_obj(); + for (Object::size_type i=0; idump_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); + f->dump_int("pool", pool); + f->dump_string("namespace", nspace); +} + +void hobject_t::generate_test_instances(list& 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, -1, "")); + o.push_back(new hobject_t(object_t("oname2"), string("okey"), CEPH_NOSNAP, + 67, 0, "n1")); + o.push_back(new hobject_t(object_t("oname3"), string("oname3"), + CEPH_SNAPDIR, 910, 1, "n2")); +} + +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; + out << "/" << o.nspace << "/" << o.pool; + return out; +} diff --git a/src/common/hobject.h b/src/common/hobject.h new file mode 100644 index 000000000000..633e471dffcd --- /dev/null +++ b/src/common/hobject.h @@ -0,0 +1,182 @@ +// -*- 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 + * + * 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 "include/types.h" +#include "include/object.h" +#include "include/cmp.h" + +#include "json_spirit/json_spirit_value.h" +#include "include/assert.h" // spirit clobbers it! + +typedef uint64_t filestore_hobject_key_t; + +namespace ceph { + class Formatter; +} + +struct hobject_t { + object_t oid; + snapid_t snap; + uint32_t hash; +private: + bool max; +public: + int64_t pool; + string nspace; + +private: + string key; + +public: + const string &get_key() const { + return key; + } + + string to_str() const; + + static bool match_hash(uint32_t to_check, uint32_t bits, uint32_t match) { + return (match & ~((~0)<hash + hobject_t get_boundary() const { + if (is_max()) + return *this; + hobject_t ret; + ret.hash = hash; + return ret; + } + + /* 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), pool(-1) { + hash = __gnu_cxx::hash()(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; + } + + /** + * Returns set S of strings such that for any object + * h where h.match(bits, mask), there is some string + * s \in S such that s is a prefix of h.to_str(). + * Furthermore, for any s \in S, s is a prefix of + * h.str() implies that h.match(bits, mask). + */ + static set get_prefixes( + uint32_t bits, + uint32_t mask, + int64_t pool); + + filestore_hobject_key_t get_filestore_key_u32() const { + assert(!max); + return _reverse_nibbles(hash); + } + filestore_hobject_key_t get_filestore_key() const { + if (max) + return 0x100000000ull; + else + return get_filestore_key_u32(); + } + + const string& get_effective_key() const { + if (key.length()) + return key; + return oid.name; + } + + void swap(hobject_t &o) { + hobject_t temp(o); + o = (*this); + (*this) = temp; + } + + string get_namespace() const { + return nspace; + } + + void encode(bufferlist& bl) const; + void decode(bufferlist::iterator& bl); + void decode(json_spirit::Value& v); + void dump(Formatter *f) const; + static void generate_test_instances(list& o); + friend bool operator<(const hobject_t&, const hobject_t&); + friend bool operator>(const hobject_t&, const hobject_t&); + friend bool operator<=(const hobject_t&, const hobject_t&); + friend bool operator>=(const hobject_t&, const hobject_t&); + friend bool operator==(const hobject_t&, const hobject_t&); + friend bool operator!=(const hobject_t&, const hobject_t&); +}; +WRITE_CLASS_ENCODER(hobject_t) + +namespace __gnu_cxx { + template<> struct hash { + size_t operator()(const hobject_t &r) const { + static hash H; + static rjhash I; + return H(r.oid) ^ I(r.snap); + } + }; +} + +ostream& operator<<(ostream& out, const hobject_t& o); + +WRITE_EQ_OPERATORS_7(hobject_t, oid, get_key(), snap, hash, max, pool, nspace) +// sort hobject_t's by +WRITE_CMP_OPERATORS_7(hobject_t, + max, + get_filestore_key(), + nspace, + pool, + get_effective_key(), + oid, + snap) + +#endif diff --git a/src/os/FDCache.h b/src/os/FDCache.h index f0f40e7bbf41..00e632f3e0f2 100644 --- a/src/os/FDCache.h +++ b/src/os/FDCache.h @@ -18,7 +18,7 @@ #include #include #include -#include "hobject.h" +#include "common/hobject.h" #include "common/Mutex.h" #include "common/Cond.h" #include "common/shared_cache.hpp" diff --git a/src/os/WBThrottle.h b/src/os/WBThrottle.h index 070de08e1230..d480a6b751c5 100644 --- a/src/os/WBThrottle.h +++ b/src/os/WBThrottle.h @@ -20,7 +20,7 @@ #include #include "include/buffer.h" #include "common/Formatter.h" -#include "os/hobject.h" +#include "common/hobject.h" #include "include/interval_set.h" #include "FDCache.h" #include "common/Thread.h" diff --git a/src/os/hobject.cc b/src/os/hobject.cc deleted file mode 100644 index d6273693c623..000000000000 --- a/src/os/hobject.cc +++ /dev/null @@ -1,193 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#include "include/types.h" -#include "hobject.h" -#include "common/Formatter.h" - -static void append_escaped(const string &in, string *out) -{ - for (string::const_iterator i = in.begin(); i != in.end(); ++i) { - if (*i == '%') { - out->push_back('%'); - out->push_back('p'); - } else if (*i == '.') { - out->push_back('%'); - out->push_back('e'); - } else if (*i == '_') { - out->push_back('%'); - out->push_back('u'); - } else { - out->push_back(*i); - } - } -} - -set hobject_t::get_prefixes( - uint32_t bits, - uint32_t mask, - int64_t pool) -{ - uint32_t len = bits; - while (len % 4 /* nibbles */) len++; - - set from; - if (bits < 32) - from.insert(mask & ~((uint32_t)(~0) << bits)); - else if (bits == 32) - from.insert(mask); - else - assert(0); - - - set to; - for (uint32_t i = bits; i < len; ++i) { - for (set::iterator j = from.begin(); - j != from.end(); - ++j) { - to.insert(*j | (1 << i)); - to.insert(*j); - } - to.swap(from); - to.clear(); - } - - char buf[20]; - char *t = buf; - uint64_t poolid(pool); - t += snprintf(t, sizeof(buf), "%.*llX", 16, (long long unsigned)poolid); - *(t++) = '.'; - string poolstr(buf, t - buf); - set ret; - for (set::iterator i = from.begin(); - i != from.end(); - ++i) { - uint32_t revhash(hobject_t::_reverse_nibbles(*i)); - snprintf(buf, sizeof(buf), "%.*X", (int)(sizeof(revhash))*2, revhash); - ret.insert(poolstr + string(buf, len/4)); - } - return ret; -} - -string hobject_t::to_str() const -{ - string out; - - char snap_with_hash[1000]; - char *t = snap_with_hash; - char *end = t + sizeof(snap_with_hash); - - uint64_t poolid(pool); - t += snprintf(t, end - t, "%.*llX", 16, (long long unsigned)poolid); - - uint32_t revhash(get_filestore_key_u32()); - t += snprintf(t, end - t, ".%.*X", 8, revhash); - - if (snap == CEPH_NOSNAP) - t += snprintf(t, end - t, ".head"); - else if (snap == CEPH_SNAPDIR) - t += snprintf(t, end - t, ".snapdir"); - else - t += snprintf(t, end - t, ".%llx", (long long unsigned)snap); - - out += string(snap_with_hash); - - out.push_back('.'); - append_escaped(oid.name, &out); - out.push_back('.'); - append_escaped(get_key(), &out); - out.push_back('.'); - append_escaped(nspace, &out); - - return out; -} - -void hobject_t::encode(bufferlist& bl) const -{ - ENCODE_START(4, 3, bl); - ::encode(key, bl); - ::encode(oid, bl); - ::encode(snap, bl); - ::encode(hash, bl); - ::encode(max, bl); - ::encode(nspace, bl); - ::encode(pool, bl); - ENCODE_FINISH(bl); -} - -void hobject_t::decode(bufferlist::iterator& bl) -{ - DECODE_START_LEGACY_COMPAT_LEN(4, 3, 3, bl); - if (struct_v >= 1) - ::decode(key, bl); - ::decode(oid, bl); - ::decode(snap, bl); - ::decode(hash, bl); - if (struct_v >= 2) - ::decode(max, bl); - else - max = false; - if (struct_v >= 4) { - ::decode(nspace, bl); - ::decode(pool, bl); - } - DECODE_FINISH(bl); -} - -void hobject_t::decode(json_spirit::Value& v) -{ - using namespace json_spirit; - Object& o = v.get_obj(); - for (Object::size_type i=0; idump_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); - f->dump_int("pool", pool); - f->dump_string("namespace", nspace); -} - -void hobject_t::generate_test_instances(list& 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, -1, "")); - o.push_back(new hobject_t(object_t("oname2"), string("okey"), CEPH_NOSNAP, - 67, 0, "n1")); - o.push_back(new hobject_t(object_t("oname3"), string("oname3"), - CEPH_SNAPDIR, 910, 1, "n2")); -} - -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; - out << "/" << o.nspace << "/" << o.pool; - return out; -} diff --git a/src/os/hobject.h b/src/os/hobject.h deleted file mode 100644 index 633e471dffcd..000000000000 --- a/src/os/hobject.h +++ /dev/null @@ -1,182 +0,0 @@ -// -*- 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 - * - * 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 "include/types.h" -#include "include/object.h" -#include "include/cmp.h" - -#include "json_spirit/json_spirit_value.h" -#include "include/assert.h" // spirit clobbers it! - -typedef uint64_t filestore_hobject_key_t; - -namespace ceph { - class Formatter; -} - -struct hobject_t { - object_t oid; - snapid_t snap; - uint32_t hash; -private: - bool max; -public: - int64_t pool; - string nspace; - -private: - string key; - -public: - const string &get_key() const { - return key; - } - - string to_str() const; - - static bool match_hash(uint32_t to_check, uint32_t bits, uint32_t match) { - return (match & ~((~0)<hash - hobject_t get_boundary() const { - if (is_max()) - return *this; - hobject_t ret; - ret.hash = hash; - return ret; - } - - /* 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), pool(-1) { - hash = __gnu_cxx::hash()(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; - } - - /** - * Returns set S of strings such that for any object - * h where h.match(bits, mask), there is some string - * s \in S such that s is a prefix of h.to_str(). - * Furthermore, for any s \in S, s is a prefix of - * h.str() implies that h.match(bits, mask). - */ - static set get_prefixes( - uint32_t bits, - uint32_t mask, - int64_t pool); - - filestore_hobject_key_t get_filestore_key_u32() const { - assert(!max); - return _reverse_nibbles(hash); - } - filestore_hobject_key_t get_filestore_key() const { - if (max) - return 0x100000000ull; - else - return get_filestore_key_u32(); - } - - const string& get_effective_key() const { - if (key.length()) - return key; - return oid.name; - } - - void swap(hobject_t &o) { - hobject_t temp(o); - o = (*this); - (*this) = temp; - } - - string get_namespace() const { - return nspace; - } - - void encode(bufferlist& bl) const; - void decode(bufferlist::iterator& bl); - void decode(json_spirit::Value& v); - void dump(Formatter *f) const; - static void generate_test_instances(list& o); - friend bool operator<(const hobject_t&, const hobject_t&); - friend bool operator>(const hobject_t&, const hobject_t&); - friend bool operator<=(const hobject_t&, const hobject_t&); - friend bool operator>=(const hobject_t&, const hobject_t&); - friend bool operator==(const hobject_t&, const hobject_t&); - friend bool operator!=(const hobject_t&, const hobject_t&); -}; -WRITE_CLASS_ENCODER(hobject_t) - -namespace __gnu_cxx { - template<> struct hash { - size_t operator()(const hobject_t &r) const { - static hash H; - static rjhash I; - return H(r.oid) ^ I(r.snap); - } - }; -} - -ostream& operator<<(ostream& out, const hobject_t& o); - -WRITE_EQ_OPERATORS_7(hobject_t, oid, get_key(), snap, hash, max, pool, nspace) -// sort hobject_t's by -WRITE_CMP_OPERATORS_7(hobject_t, - max, - get_filestore_key(), - nspace, - pool, - get_effective_key(), - oid, - snap) - -#endif diff --git a/src/osd/SnapMapper.h b/src/osd/SnapMapper.h index 560cc43497f6..f0d0baa21908 100644 --- a/src/osd/SnapMapper.h +++ b/src/osd/SnapMapper.h @@ -21,7 +21,7 @@ #include #include "common/map_cacher.hpp" -#include "os/hobject.h" +#include "common/hobject.h" #include "include/buffer.h" #include "include/encoding.h" #include "include/object.h" diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 312eb81e3fd0..da139b853b16 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -26,7 +26,7 @@ #include "include/interval_set.h" #include "common/snap_types.h" #include "common/Formatter.h" -#include "os/hobject.h" +#include "common/hobject.h" #include "Watch.h" #define CEPH_OSD_ONDISK_MAGIC "ceph osd volume v026" diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index a6f7cfb7883d..514c76fc1a89 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -75,7 +75,7 @@ TYPE(ObjectStore::Transaction) #include "os/SequencerPosition.h" TYPE(SequencerPosition) -#include "os/hobject.h" +#include "common/hobject.h" TYPE(hobject_t) #include "mon/AuthMonitor.h"