osd: redo pg_t encoding with 64-bit pool id

Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
Sage Weil 2011-08-25 13:30:49 -07:00 committed by Sage Weil
parent d8f1f1dd29
commit 877aa92b80
8 changed files with 99 additions and 44 deletions

View File

@ -72,7 +72,7 @@ public:
head.flags =
(req->flags & ~(CEPH_OSD_FLAG_ONDISK|CEPH_OSD_FLAG_ONNVRAM|CEPH_OSD_FLAG_ACK)) | acktype;
oid = req->oid;
head.layout.ol_pgid = req->pgid.v;
head.layout.ol_pgid = req->pgid.get_old_pg();
head.osdmap_epoch = e;
head.reassert_version = req->reassert_version;
}

View File

@ -2146,7 +2146,7 @@ bool OSDMonitor::prepare_pool_op_create(MPoolOp *m)
return true;
}
int OSDMonitor::_prepare_remove_pool(int pool)
int OSDMonitor::_prepare_remove_pool(uint64_t pool)
{
dout(10) << "_prepare_remove_pool " << pool << dendl;
if (pending_inc.old_pools.count(pool)) {

View File

@ -89,7 +89,7 @@ private:
bool preprocess_pgtemp(class MOSDPGTemp *m);
bool prepare_pgtemp(class MOSDPGTemp *m);
int _prepare_remove_pool(int pool);
int _prepare_remove_pool(uint64_t pool);
bool preprocess_pool_op ( class MPoolOp *m);
bool preprocess_pool_op_create ( class MPoolOp *m);

View File

@ -581,9 +581,9 @@ void PGMonitor::register_pg(pg_pool_t& pool, pg_t pgid, epoch_t epoch, bool new_
parent = pgid;
while (1) {
// remove most significant bit
int msb = pool.calc_bits_of(parent.v.ps);
int msb = pool.calc_bits_of(parent.ps());
if (!msb) break;
parent.v.ps = parent.v.ps & ~(1<<(msb-1));
parent.set_ps(parent.ps() & ~(1<<(msb-1)));
split_bits++;
dout(10) << " is " << pgid << " parent " << parent << " ?" << dendl;
//if (parent.u.pg.ps < mon->osdmon->osdmap.get_pgp_num()) {

View File

@ -811,7 +811,7 @@ private:
ceph_object_layout ol;
pg_t pgid = object_locator_to_pg(oid, loc);
ol.ol_pgid = pgid.v;
ol.ol_pgid = pgid.get_old_pg().v;
ol.ol_stripe_unit = 0;
return ol;
}

View File

@ -26,25 +26,25 @@ void osd_reqid_t::decode(bufferlist::iterator &bl)
int pg_t::print(char *o, int maxlen) const
{
if (preferred() >= 0)
return snprintf(o, maxlen, "%d.%xp%d", pool(), ps(), preferred());
return snprintf(o, maxlen, "%llu.%xp%d", (unsigned long long)pool(), ps(), preferred());
else
return snprintf(o, maxlen, "%d.%x", pool(), ps());
return snprintf(o, maxlen, "%llu.%x", (unsigned long long)pool(), ps());
}
bool pg_t::parse(const char *s)
{
int ppool;
int pseed;
int pref;
int r = sscanf(s, "%d.%xp%d", &ppool, &pseed, &pref);
uint64_t ppool;
uint32_t pseed;
int32_t pref;
int r = sscanf(s, "%llu.%xp%d", (long long unsigned *)&ppool, &pseed, &pref);
if (r < 2)
return false;
v.pool = ppool;
v.ps = pseed;
m_pool = ppool;
m_seed = pseed;
if (r == 3)
v.preferred = pref;
m_preferred = pref;
else
v.preferred = -1;
m_preferred = -1;
return true;
}
@ -363,9 +363,9 @@ SnapContext pg_pool_t::get_snap_context() const
pg_t pg_pool_t::raw_pg_to_pg(pg_t pg) const
{
if (pg.preferred() >= 0 && v.lpg_num)
pg.v.ps = ceph_stable_mod(pg.ps(), v.lpg_num, lpg_num_mask);
pg.set_ps(ceph_stable_mod(pg.ps(), v.lpg_num, lpg_num_mask));
else
pg.v.ps = ceph_stable_mod(pg.ps(), v.pg_num, pg_num_mask);
pg.set_ps(ceph_stable_mod(pg.ps(), v.pg_num, pg_num_mask));
return pg;
}

View File

@ -89,8 +89,6 @@ namespace __gnu_cxx {
// pg stuff
typedef uint16_t ps_t;
// object namespaces
#define CEPH_METADATA_NS 1
#define CEPH_DATA_NS 2
@ -104,32 +102,97 @@ enum {
CEPH_RBD_RULE,
};
//#define CEPH_POOL(poolset, size) (((poolset) << 8) + (size))
#define OSD_SUPERBLOCK_POBJECT sobject_t(object_t("osd_superblock"), 0)
// placement seed (a hash value)
typedef uint32_t ps_t;
// old (v1) pg_t encoding (wrap old struct ceph_pg)
struct old_pg_t {
ceph_pg v;
void encode(bufferlist& bl) const {
::encode_raw(v, bl);
}
void decode(bufferlist::iterator& bl) {
::decode_raw(v, bl);
}
};
WRITE_CLASS_ENCODER(old_pg_t)
// placement group id
struct pg_t {
struct ceph_pg v;
uint64_t m_pool;
uint32_t m_seed;
int32_t m_preferred;
pg_t() { memset(&v, 0, sizeof(v)); }
pg_t(const pg_t& o) { v = o.v; }
pg_t(ps_t seed, int pool_, int pref) {
v.ps = seed;
v.pool = pool_;
v.preferred = pref; // hack: avoid negative.
pg_t() : m_pool(0), m_seed(0), m_preferred(-1) {}
pg_t(ps_t seed, uint64_t pool, int pref) {
m_seed = seed;
m_pool = pool;
m_preferred = pref;
}
pg_t(const ceph_pg& cpg) {
v = cpg;
m_pool = cpg.pool;
m_seed = cpg.ps;
m_preferred = (__s16)cpg.preferred;
}
old_pg_t get_old_pg() const {
old_pg_t o;
assert(m_pool < 0xffffffffull);
o.v.pool = m_pool;
o.v.ps = m_seed;
o.v.preferred = (__s16)m_preferred;
return o;
}
pg_t(const old_pg_t& opg) {
*this = opg.v;
}
ps_t ps() const { return v.ps; }
int pool() const { return v.pool; }
int preferred() const { return (__s16)v.preferred; } // hack: avoid negative.
ps_t ps() const {
return m_seed;
}
uint64_t pool() const {
return m_pool;
}
int32_t preferred() const {
return m_preferred;
}
void set_ps(ps_t p) {
m_seed = p;
}
void set_pool(uint64_t p) {
m_pool = p;
}
void set_preferred(int32_t osd) {
m_preferred = osd;
}
int print(char *o, int maxlen) const;
bool parse(const char *s);
} __attribute__ ((packed));
void encode(bufferlist& bl) const {
__u8 v = 1;
::encode(v, bl);
::encode(m_pool, bl);
::encode(m_seed, bl);
::encode(m_preferred, bl);
}
void decode(bufferlist::iterator& bl) {
__u8 v;
::decode(v, bl);
::decode(m_pool, bl);
::decode(m_seed, bl);
::decode(m_preferred, bl);
}
void decode_old(bufferlist::iterator& bl) {
old_pg_t opg;
::decode(opg, bl);
*this = opg;
}
};
WRITE_CLASS_ENCODER(pg_t)
inline bool operator<(const pg_t& l, const pg_t& r) {
return l.pool() < r.pool() ||
@ -162,14 +225,6 @@ inline bool operator>=(const pg_t& l, const pg_t& r) {
(l.preferred() == r.preferred() && (l.ps() >= r.ps()))));
}
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);
}
ostream& operator<<(ostream& out, const pg_t &pg);
namespace __gnu_cxx {
@ -178,7 +233,7 @@ namespace __gnu_cxx {
size_t operator()( const pg_t& x ) const
{
static hash<uint32_t> H;
return H(x.pool() ^ x.ps() ^ x.preferred());
return H((x.pool() & 0xffffffff) ^ (x.pool() >> 32) ^ x.ps() ^ x.preferred());
}
};
}

View File

@ -202,7 +202,7 @@ int main(int argc, const char **argv)
ceph_object_layout ol = osdmap.make_object_layout(oid, 0);
pg_t pgid;
pgid.v = ol.ol_pgid;
pgid = ol.ol_pgid;
vector<int> acting;
osdmap.pg_to_acting_osds(pgid, acting);