libceph: introduce ceph_spg, ceph_pg_to_primary_shard()

Store both raw pgid and actual spgid in ceph_osd_request_target.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
Ilya Dryomov
2017-06-15 16:30:53 +02:00
parent 8e48cf00c4
commit dc98ff7230
5 changed files with 60 additions and 4 deletions

View File

@@ -2265,6 +2265,39 @@ out:
WARN_ON(!osds_valid(up) || !osds_valid(acting));
}
bool ceph_pg_to_primary_shard(struct ceph_osdmap *osdmap,
const struct ceph_pg *raw_pgid,
struct ceph_spg *spgid)
{
struct ceph_pg_pool_info *pi;
struct ceph_pg pgid;
struct ceph_osds up, acting;
int i;
pi = ceph_pg_pool_by_id(osdmap, raw_pgid->pool);
if (!pi)
return false;
raw_pg_to_pg(pi, raw_pgid, &pgid);
if (ceph_can_shift_osds(pi)) {
spgid->pgid = pgid; /* struct */
spgid->shard = CEPH_SPG_NOSHARD;
return true;
}
ceph_pg_to_up_acting_osds(osdmap, &pgid, &up, &acting);
for (i = 0; i < acting.size; i++) {
if (acting.osds[i] == acting.primary) {
spgid->pgid = pgid; /* struct */
spgid->shard = i;
return true;
}
}
return false;
}
/*
* Return acting primary for given PG, or -1 if none.
*/