aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorIlya Dryomov <ilya.dryomov@inktank.com>2014-03-24 11:12:47 -0400
committerSage Weil <sage@inktank.com>2014-04-05 00:08:10 -0400
commit2bd93d4d7ec2dd461cfb87c6d8a9b1ef9b30de08 (patch)
tree28aba9466ec7d7142799d97279eafc28eb7da938 /net
parent2abebdbca7997422bfab6bf8b6559384a6b95294 (diff)
libceph: introduce pg_to_raw_osds() and raw_to_up_osds() helpers
pg_to_raw_osds() helper for computing a raw (crush) set, which can contain non-existant and down osds. raw_to_up_osds() helper for pruning non-existant and down osds from the raw set, therefore transforming it into an up set, and determining up primary. Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com> Reviewed-by: Alex Elder <elder@linaro.org>
Diffstat (limited to 'net')
-rw-r--r--net/ceph/osdmap.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 9568e6221852..b8bbef058019 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -1521,6 +1521,82 @@ static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
1521} 1521}
1522 1522
1523/* 1523/*
1524 * Calculate raw (crush) set for given pgid.
1525 *
1526 * Return raw set length, or error.
1527 */
1528static int pg_to_raw_osds(struct ceph_osdmap *osdmap,
1529 struct ceph_pg_pool_info *pool,
1530 struct ceph_pg pgid, u32 pps, int *osds)
1531{
1532 int ruleno;
1533 int len;
1534
1535 /* crush */
1536 ruleno = crush_find_rule(osdmap->crush, pool->crush_ruleset,
1537 pool->type, pool->size);
1538 if (ruleno < 0) {
1539 pr_err("no crush rule: pool %lld ruleset %d type %d size %d\n",
1540 pgid.pool, pool->crush_ruleset, pool->type,
1541 pool->size);
1542 return -ENOENT;
1543 }
1544
1545 len = do_crush(osdmap, ruleno, pps, osds,
1546 min_t(int, pool->size, CEPH_PG_MAX_SIZE),
1547 osdmap->osd_weight, osdmap->max_osd);
1548 if (len < 0) {
1549 pr_err("error %d from crush rule %d: pool %lld ruleset %d type %d size %d\n",
1550 len, ruleno, pgid.pool, pool->crush_ruleset,
1551 pool->type, pool->size);
1552 return len;
1553 }
1554
1555 return len;
1556}
1557
1558/*
1559 * Given raw set, calculate up set and up primary.
1560 *
1561 * Return up set length. *primary is set to up primary osd id, or -1
1562 * if up set is empty.
1563 */
1564static int raw_to_up_osds(struct ceph_osdmap *osdmap,
1565 struct ceph_pg_pool_info *pool,
1566 int *osds, int len, int *primary)
1567{
1568 int up_primary = -1;
1569 int i;
1570
1571 if (ceph_can_shift_osds(pool)) {
1572 int removed = 0;
1573
1574 for (i = 0; i < len; i++) {
1575 if (ceph_osd_is_down(osdmap, osds[i])) {
1576 removed++;
1577 continue;
1578 }
1579 if (removed)
1580 osds[i - removed] = osds[i];
1581 }
1582
1583 len -= removed;
1584 if (len > 0)
1585 up_primary = osds[0];
1586 } else {
1587 for (i = len - 1; i >= 0; i--) {
1588 if (ceph_osd_is_down(osdmap, osds[i]))
1589 osds[i] = CRUSH_ITEM_NONE;
1590 else
1591 up_primary = osds[i];
1592 }
1593 }
1594
1595 *primary = up_primary;
1596 return len;
1597}
1598
1599/*
1524 * Return acting set for given pgid. 1600 * Return acting set for given pgid.
1525 */ 1601 */
1526int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid, 1602int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid,