]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: kill int <-> pg_t conversions
authorSage Weil <sage@newdream.net>
Wed, 4 Nov 2009 20:24:39 +0000 (12:24 -0800)
committerSage Weil <sage@newdream.net>
Wed, 4 Nov 2009 20:24:39 +0000 (12:24 -0800)
These are messy and asking for trouble.  And a cleaner
coll_t paves the way for real named coll_t's down the
line.

src/TODO
src/osd/Ager.cc
src/osd/OSD.cc
src/osd/PG.cc
src/osd/PG.h
src/osd/osd_types.h
src/streamtest.cc

index c9d09e91420d8eb4d4ac37363818dbc6c4cb6256..4beb239d53b472259028ace2e8bfdc2306a2bc25 100644 (file)
--- a/src/TODO
+++ b/src/TODO
@@ -45,6 +45,8 @@ v0.17
 
 v0.18
 - basic ENOSPC handling
+- big endian fix
+
 
 - qa
 - osd: rebuild pg log
index c52c93b3e1eb342e80f9e71fa329d1d84d027e2c..7e4502962525d8d87ea0b3102b263de03a51df25 100644 (file)
@@ -118,7 +118,7 @@ uint64_t Ager::age_fill(float pc, utime_t until) {
       sbl.substr_of(bl, 0, t);
       ObjectStore::Transaction tr;
       sobject_t oid(poid, 0);
-      tr.write(0, oid, off, t, sbl);
+      tr.write(coll_t(), oid, off, t, sbl);
       store->apply_transaction(tr);
       off += t;
       s -= t;
@@ -162,7 +162,7 @@ void Ager::age_empty(float pc) {
     
     ObjectStore::Transaction t;
     sobject_t oid(poid, 0);
-    t.remove(0, oid);
+    t.remove(coll_t(), oid);
     store->apply_transaction(t);
     age_free_oids.push_back(poid);
   }
index ba208fe62285ae21b07f50e615afb7afcd940cf1..7b35605cae9d785581cd6d3e56f531cbfacbdc87 100644 (file)
@@ -161,7 +161,7 @@ int OSD::mkfs(const char *dev, const char *jdev, ceph_fsid_t fsid, int whoami)
     object_t oid("disk_bw_test");
     for (int i=0; i<1000; i++) {
       ObjectStore::Transaction t;
-      t.write(0, sobject_t(oid, 0), i*bl.length(), bl.length(), bl);
+      t.write(meta_coll, sobject_t(oid, 0), i*bl.length(), bl.length(), bl);
       store->apply_transaction(t);
     }
     store->sync();
@@ -169,7 +169,7 @@ int OSD::mkfs(const char *dev, const char *jdev, ceph_fsid_t fsid, int whoami)
     end -= start;
     cout << "measured " << (1000.0 / (double)end) << " mb/sec" << std::endl;
     ObjectStore::Transaction tr;
-    tr.remove(0, sobject_t(oid, 0));
+    tr.remove(meta_coll, sobject_t(oid, 0));
     store->apply_transaction(tr);
     
     // set osd weight
@@ -180,8 +180,8 @@ int OSD::mkfs(const char *dev, const char *jdev, ceph_fsid_t fsid, int whoami)
   ::encode(sb, bl);
 
   ObjectStore::Transaction t;
-  t.create_collection(0);
-  t.write(0, OSD_SUPERBLOCK_POBJECT, 0, bl.length(), bl);
+  t.create_collection(meta_coll);
+  t.write(meta_coll, OSD_SUPERBLOCK_POBJECT, 0, bl.length(), bl);
   int r = store->apply_transaction(t);
   store->umount();
   delete store;
@@ -199,7 +199,7 @@ int OSD::peek_super(const char *dev, nstring& magic, ceph_fsid_t& fsid, int& who
 
   OSDSuperblock sb;
   bufferlist bl;
-  err = store->read(0, OSD_SUPERBLOCK_POBJECT, 0, 0, bl);
+  err = store->read(meta_coll, OSD_SUPERBLOCK_POBJECT, 0, 0, bl);
   store->umount();
   delete store;
 
@@ -556,13 +556,13 @@ void OSD::write_superblock(ObjectStore::Transaction& t)
 
   bufferlist bl;
   ::encode(superblock, bl);
-  t.write(0, OSD_SUPERBLOCK_POBJECT, 0, bl.length(), bl);
+  t.write(meta_coll, OSD_SUPERBLOCK_POBJECT, 0, bl.length(), bl);
 }
 
 int OSD::read_superblock()
 {
   bufferlist bl;
-  int r = store->read(0, OSD_SUPERBLOCK_POBJECT, 0, 0, bl);
+  int r = store->read(meta_coll, OSD_SUPERBLOCK_POBJECT, 0, 0, bl);
   if (r < 0)
     return r;
 
@@ -732,7 +732,7 @@ void OSD::load_pgs()
   for (vector<coll_t>::iterator it = ls.begin();
        it != ls.end();
        it++) {
-    if (*it == 0)
+    if (*it == meta_coll)
       continue;
     if (it->snap != CEPH_NOSNAP)
       continue;
@@ -1760,7 +1760,7 @@ void OSD::handle_osd_map(MOSDMap *m)
        p != m->maps.end();
        p++) {
     sobject_t poid = get_osdmap_pobject_name(p->first);
-    if (store->exists(0, poid)) {
+    if (store->exists(meta_coll, poid)) {
       dout(10) << "handle_osd_map already had full map epoch " << p->first << dendl;
       logger->inc(l_osd_mapfdup);
       bufferlist bl;
@@ -1771,7 +1771,7 @@ void OSD::handle_osd_map(MOSDMap *m)
 
     dout(10) << "handle_osd_map got full map epoch " << p->first << dendl;
     ObjectStore::Transaction ft;
-    ft.write(0, poid, 0, p->second.length(), p->second);  // store _outside_ transaction; activate_map reads it.
+    ft.write(meta_coll, poid, 0, p->second.length(), p->second);  // store _outside_ transaction; activate_map reads it.
     int r = store->apply_transaction(ft);
     if (r) {
       char buf[80];
@@ -1792,7 +1792,7 @@ void OSD::handle_osd_map(MOSDMap *m)
        p != m->incremental_maps.end();
        p++) {
     sobject_t poid = get_inc_osdmap_pobject_name(p->first);
-    if (store->exists(0, poid)) {
+    if (store->exists(meta_coll, poid)) {
       dout(10) << "handle_osd_map already had incremental map epoch " << p->first << dendl;
       logger->inc(l_osd_mapidup);
       bufferlist bl;
@@ -1803,7 +1803,7 @@ void OSD::handle_osd_map(MOSDMap *m)
 
     dout(10) << "handle_osd_map got incremental map epoch " << p->first << dendl;
     ObjectStore::Transaction ft;
-    ft.write(0, poid, 0, p->second.length(), p->second);  // store _outside_ transaction; activate_map reads it.
+    ft.write(meta_coll, poid, 0, p->second.length(), p->second);  // store _outside_ transaction; activate_map reads it.
     int r = store->apply_transaction(ft);
     if (r) {
       char buf[80];
@@ -1831,7 +1831,7 @@ void OSD::handle_osd_map(MOSDMap *m)
     OSDMap::Incremental inc;
 
     if (m->incremental_maps.count(cur+1) ||
-        store->exists(0, get_inc_osdmap_pobject_name(cur+1))) {
+        store->exists(meta_coll, get_inc_osdmap_pobject_name(cur+1))) {
       dout(10) << "handle_osd_map decoding inc map epoch " << cur+1 << dendl;
       
       bufferlist bl;
@@ -1851,7 +1851,7 @@ void OSD::handle_osd_map(MOSDMap *m)
       bl.clear();
       osdmap->encode(bl);
       ObjectStore::Transaction ft;
-      ft.write(0, get_osdmap_pobject_name(cur+1), 0, bl.length(), bl);
+      ft.write(meta_coll, get_osdmap_pobject_name(cur+1), 0, bl.length(), bl);
       int r = store->apply_transaction(ft);
       if (r) {
        char buf[80];
@@ -1876,7 +1876,7 @@ void OSD::handle_osd_map(MOSDMap *m)
       }
     }
     else if (m->maps.count(cur+1) ||
-             store->exists(0, get_osdmap_pobject_name(cur+1))) {
+             store->exists(meta_coll, get_osdmap_pobject_name(cur+1))) {
       dout(10) << "handle_osd_map decoding full map epoch " << cur+1 << dendl;
       bufferlist bl;
       if (m->maps.count(cur+1))
@@ -2310,12 +2310,12 @@ void OSD::send_incremental_map(epoch_t since, const entity_inst_t& inst, bool fu
 
 bool OSD::get_map_bl(epoch_t e, bufferlist& bl)
 {
-  return store->read(0, get_osdmap_pobject_name(e), 0, 0, bl) >= 0;
+  return store->read(meta_coll, get_osdmap_pobject_name(e), 0, 0, bl) >= 0;
 }
 
 bool OSD::get_inc_map_bl(epoch_t e, bufferlist& bl)
 {
-  return store->read(0, get_inc_osdmap_pobject_name(e), 0, 0, bl) >= 0;
+  return store->read(meta_coll, get_inc_osdmap_pobject_name(e), 0, 0, bl) >= 0;
 }
 
 OSDMap *OSD::get_map(epoch_t epoch)
@@ -3270,7 +3270,7 @@ void OSD::_remove_pg(PG *pg)
   {
     ObjectStore::Transaction t;
     pg->write_info(t);
-    t.remove(0, pg->log_oid);
+    t.remove(meta_coll, pg->log_oid);
     int tr = store->apply_transaction(t);
     assert(tr == 0);
   }
index 6a969382fe3e3e674e7d53b96bec4580f1d570d1..b890f28e9d5c5ca61e03e6cd9872c3c3166babcc 100644 (file)
@@ -1842,8 +1842,8 @@ void PG::write_log(ObjectStore::Transaction& t)
   ondisklog.head = bl.length();
   
   // write it
-  t.remove(0, log_oid );
-  t.write(0, log_oid , 0, bl.length(), bl);
+  t.remove(meta_coll, log_oid );
+  t.write(meta_coll, log_oid , 0, bl.length(), bl);
 
   bufferlist blb(sizeof(ondisklog));
   ::encode(ondisklog, blb);
@@ -1900,7 +1900,7 @@ void PG::trim_ondisklog_to(ObjectStore::Transaction& t, eversion_t v)
   t.collection_setattr(coll_t::build_pg_coll(info.pgid), "ondisklog", blb);
 
   if (!g_conf.osd_preserve_trimmed_log)
-    t.zero(0, log_oid, 0, ondisklog.tail & ~4095);
+    t.zero(meta_coll, log_oid, 0, ondisklog.tail & ~4095);
 }
 
 void PG::trim_peers()
@@ -1943,7 +1943,7 @@ void PG::append_log(ObjectStore::Transaction &t, bufferlist& bl,
   if (ondisklog.head % 4096 < (ondisklog.head + bl.length()) % 4096)
     ondisklog.block_map[ondisklog.head] = log_version;  // log_version is last event in prev. block
 
-  t.write(0, log_oid, ondisklog.head, bl.length(), bl );
+  t.write(meta_coll, log_oid, ondisklog.head, bl.length(), bl );
   
   ondisklog.head += bl.length();
 
@@ -1971,7 +1971,7 @@ void PG::read_log(ObjectStore *store)
   if (ondisklog.head > 0) {
     // read
     bufferlist bl;
-    store->read(0, log_oid, ondisklog.tail, ondisklog.length(), bl);
+    store->read(meta_coll, log_oid, ondisklog.tail, ondisklog.length(), bl);
     if (bl.length() < ondisklog.length()) {
       dout(0) << "read_log got " << bl.length() << " bytes, expected " 
              << ondisklog.head << "-" << ondisklog.tail << "="
index a85fdcc142d775b9138ae4057f1762b7e4ecc2c0..81baeebc3d1d71f44bc92df6fae03c46dd4b215b 100644 (file)
@@ -133,9 +133,9 @@ public:
       }
     } history;
     
-    Info(pg_t p=0) : pgid(p), 
-                     log_backlog(false)
-    { }
+    Info() : log_backlog(false) {}
+    Info(pg_t p) : pgid(p), log_backlog(false) { }
+
     bool is_uptodate() const { return last_update == last_complete; }
     bool is_empty() const { return last_update.version == 0; }
     bool dne() const { return history.epoch_created == 0; }
index 5c6757dc4b092a8c622ab07037e497391fc1b7fb..d49ae0a7931a5f59bd6b07c0b4e96448463a17d9 100644 (file)
@@ -118,17 +118,14 @@ struct pg_t {
     v.pool = pool;
     v.preferred = pref;   // hack: avoid negative.
   }
-  pg_t(uint64_t n) { *(__le64*)&v = n; }
   pg_t(const ceph_pg& cpg) {
     v = cpg;
   }
 
-  ps_t ps() { return v.ps; }
-  int pool() { return v.pool; }
-  int preferred() { return (__s16)v.preferred; }   // hack: avoid negative.
+  ps_t ps() const { return v.ps; }
+  int pool() const { return v.pool; }
+  int preferred() const { return (__s16)v.preferred; }   // hack: avoid negative.
   
-  operator uint64_t() const { return *(__le64*)&v; }
-
   /*coll_t to_coll() const {
     return coll_t(u.pg64, 0); 
   }
@@ -160,6 +157,26 @@ struct pg_t {
 
 } __attribute__ ((packed));
 
+inline bool operator<(const pg_t& l, const pg_t& r) {
+  return memcmp(&l, &r, sizeof(l)) < 0;
+}
+inline bool operator<=(const pg_t& l, const pg_t& r) {
+  return memcmp(&l, &r, sizeof(l)) <= 0;
+}
+inline bool operator==(const pg_t& l, const pg_t& r) {
+  return memcmp(&l, &r, sizeof(l)) == 0;
+}
+inline bool operator!=(const pg_t& l, const pg_t& r) {
+  return memcmp(&l, &r, sizeof(l)) != 0;
+}
+inline bool operator>(const pg_t& l, const pg_t& r) {
+  return memcmp(&l, &r, sizeof(l)) > 0;
+}
+inline bool operator>=(const pg_t& l, const pg_t& r) {
+  return memcmp(&l, &r, sizeof(l)) >= 0;
+}
+
+
 inline void encode(pg_t pgid, bufferlist& bl) { encode_raw(pgid.v, bl); }
 inline void decode(pg_t &pgid, bufferlist::iterator& p) { 
   decode_raw(pgid.v, p); 
@@ -183,8 +200,8 @@ namespace __gnu_cxx {
   {
     size_t operator()( const pg_t& x ) const
     {
-      static rjhash<uint64_t> H;
-      return H(x);
+      static hash<uint32_t> H;
+      return H(x.pool() ^ x.ps() ^ x.preferred());
     }
   };
 }
@@ -196,7 +213,8 @@ struct coll_t {
   pg_t pgid;
   snapid_t snap;
 
-  coll_t(__u64 p=0, snapid_t s=0) : pgid(p), snap(s) {}
+  coll_t() : snap(0) {}
+  coll_t(pg_t p, snapid_t s) : pgid(p), snap(s) {}
   
   static coll_t build_pg_coll(pg_t p) {
     return coll_t(p, CEPH_NOSNAP);
@@ -271,7 +289,7 @@ inline bool operator>=(const coll_t& l, const coll_t& r) {
 namespace __gnu_cxx {
   template<> struct hash<coll_t> {
     size_t operator()(const coll_t &c) const { 
-      static rjhash<uint32_t> H;
+      static hash<pg_t> H;
       static rjhash<uint64_t> I;
       return H(c.pgid) ^ I(c.snap);
     }
@@ -279,6 +297,8 @@ namespace __gnu_cxx {
 }
 
 
+const coll_t meta_coll;
+
 
 
 inline ostream& operator<<(ostream& out, const ceph_object_layout &ol)
index a8b76e4a1eeb35bdd1caf52c4aeeba0ea8e9b6c5..81da54ef980242460a6bd9538f0752217851dfca 100644 (file)
@@ -107,7 +107,7 @@ int main(int argc, const char **argv)
   }
 
   ObjectStore::Transaction ft;
-  ft.create_collection(0);
+  ft.create_collection(coll_t());
   fs->apply_transaction(ft);
 
   utime_t now = g_clock.now();
@@ -121,7 +121,7 @@ int main(int argc, const char **argv)
     utime_t start = now;
     set_start(pos, now);
     ObjectStore::Transaction t;
-    t.write(0, poid, pos, bytes, bl);
+    t.write(coll_t(), poid, pos, bytes, bl);
     fs->apply_transaction(t, new C_Commit(pos));
     now = g_clock.now();
     set_ack(pos, now);