aboutsummaryrefslogtreecommitdiffstats
path: root/net/ceph/osdmap.c
diff options
context:
space:
mode:
authorIlya Dryomov <ilya.dryomov@inktank.com>2014-03-24 11:12:49 -0400
committerSage Weil <sage@inktank.com>2014-04-05 00:08:19 -0400
commitc4c1228525a2cbf9e06657b01135391700c1ec14 (patch)
tree5e267ec7530a19d566a8700e20c926a5c45d102f /net/ceph/osdmap.c
parent47ec1f3cc46dde00deb34922dbffdeda254ad76d (diff)
libceph: redo ceph_calc_pg_primary() in terms of ceph_calc_pg_acting()
Reimplement ceph_calc_pg_primary() in terms of ceph_calc_pg_acting() and get rid of the now unused calc_pg_raw(). Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com> Reviewed-by: Alex Elder <elder@linaro.org>
Diffstat (limited to 'net/ceph/osdmap.c')
-rw-r--r--net/ceph/osdmap.c79
1 files changed, 4 insertions, 75 deletions
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index ae8f367c5291..408d14826b5e 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -1456,71 +1456,6 @@ static int do_crush(struct ceph_osdmap *map, int ruleno, int x,
1456} 1456}
1457 1457
1458/* 1458/*
1459 * Calculate raw osd vector for the given pgid. Return pointer to osd
1460 * array, or NULL on failure.
1461 */
1462static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
1463 int *osds, int *num)
1464{
1465 struct ceph_pg_mapping *pg;
1466 struct ceph_pg_pool_info *pool;
1467 int ruleno;
1468 int r;
1469 u32 pps;
1470
1471 pool = __lookup_pg_pool(&osdmap->pg_pools, pgid.pool);
1472 if (!pool)
1473 return NULL;
1474
1475 /* pg_temp? */
1476 pgid.seed = ceph_stable_mod(pgid.seed, pool->pg_num,
1477 pool->pg_num_mask);
1478 pg = __lookup_pg_mapping(&osdmap->pg_temp, pgid);
1479 if (pg) {
1480 *num = pg->pg_temp.len;
1481 return pg->pg_temp.osds;
1482 }
1483
1484 /* crush */
1485 ruleno = crush_find_rule(osdmap->crush, pool->crush_ruleset,
1486 pool->type, pool->size);
1487 if (ruleno < 0) {
1488 pr_err("no crush rule pool %lld ruleset %d type %d size %d\n",
1489 pgid.pool, pool->crush_ruleset, pool->type,
1490 pool->size);
1491 return NULL;
1492 }
1493
1494 if (pool->flags & CEPH_POOL_FLAG_HASHPSPOOL) {
1495 /* hash pool id and seed sothat pool PGs do not overlap */
1496 pps = crush_hash32_2(CRUSH_HASH_RJENKINS1,
1497 ceph_stable_mod(pgid.seed, pool->pgp_num,
1498 pool->pgp_num_mask),
1499 pgid.pool);
1500 } else {
1501 /*
1502 * legacy ehavior: add ps and pool together. this is
1503 * not a great approach because the PGs from each pool
1504 * will overlap on top of each other: 0.5 == 1.4 ==
1505 * 2.3 == ...
1506 */
1507 pps = ceph_stable_mod(pgid.seed, pool->pgp_num,
1508 pool->pgp_num_mask) +
1509 (unsigned)pgid.pool;
1510 }
1511 r = do_crush(osdmap, ruleno, pps, osds, min_t(int, pool->size, *num),
1512 osdmap->osd_weight, osdmap->max_osd);
1513 if (r < 0) {
1514 pr_err("error %d from crush rule: pool %lld ruleset %d type %d"
1515 " size %d\n", r, pgid.pool, pool->crush_ruleset,
1516 pool->type, pool->size);
1517 return NULL;
1518 }
1519 *num = r;
1520 return osds;
1521}
1522
1523/*
1524 * Calculate raw (crush) set for given pgid. 1459 * Calculate raw (crush) set for given pgid.
1525 * 1460 *
1526 * Return raw set length, or error. 1461 * Return raw set length, or error.
@@ -1776,17 +1711,11 @@ int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
1776 */ 1711 */
1777int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, struct ceph_pg pgid) 1712int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, struct ceph_pg pgid)
1778{ 1713{
1779 int rawosds[CEPH_PG_MAX_SIZE], *osds; 1714 int osds[CEPH_PG_MAX_SIZE];
1780 int i, num = CEPH_PG_MAX_SIZE; 1715 int primary;
1781 1716
1782 osds = calc_pg_raw(osdmap, pgid, rawosds, &num); 1717 ceph_calc_pg_acting(osdmap, pgid, osds, &primary);
1783 if (!osds)
1784 return -1;
1785 1718
1786 /* primary is first up osd */ 1719 return primary;
1787 for (i = 0; i < num; i++)
1788 if (ceph_osd_is_up(osdmap, osds[i]))
1789 return osds[i];
1790 return -1;
1791} 1720}
1792EXPORT_SYMBOL(ceph_calc_pg_primary); 1721EXPORT_SYMBOL(ceph_calc_pg_primary);